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 - 我们是谁 (樱桃科尔私人战利品) 完整官方版本

但它取代了 $ 符号。如何防止函数上的 $ 符号?

修改第一个preg_replace以跳过$

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

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