php 正则表达式阻止替换 $ 符号

php regex prevent replacing $ symbol

我有一个 php 函数,它从字符串生成标签:

function generate_tags($text)
{
    $string = preg_replace('/[^\p{L}\p{N}\s]/u', ' ', $text);
    $string = preg_replace('/\s+/', ' ', $string);
    $string = mb_strtolower($string, 'UTF-8');
    $keywords = explode(' ', trim($string));
    foreach($keywords as $key => $value)
    {
        if((strlen($value)) < 1)
        {
            unset($keywords[$key]);
            continue;
        }
    }
    $result = array_unique($keywords);
    $result = array_values($result);
    return $result;
}

字符串是: Ke$ha - We Are Who We Are (Cherry Cole Private Booty) 正式版

但它取代了 $ 符号。如何防止函数中出现 $ 符号?

修改第一个preg_replace以跳过$

$string = preg_replace('/[^\p{L}\p{N}\s$]/u', ' ', $text);

修改第一个 preg_replace 以跳过 $:$string = preg_replace('/[^\p{L}\p{N}\s$]/u', ' ', $text); 您只需按下投票按钮下方的勾号即可。