此问题已经在这里有了答案:
$search="#hairbeauty";
$content="Blab blab #hairbeauty blab";
$result=preg_match('/\b('.$search.')\b/i',$content);
它总是返回false ...但是if 我从$ search和$ content中删除了hashsymbol(#),它返回true ...
所以如何处理这种情况...我的确切要求是处理精确的单词匹配包含特殊字符] ..
提前感谢。
$ search =“#hairbeauty”; $ content =“ Blab blab #hairbeauty blab”; $ result = preg_match('/ \ b('。$ search。')\ b / i',$ content);它总是返回false ...但是如果我从$ search和$ content中删除了hashsymbol(#),...
在正则表达式中,哈希符号不算作单词的一部分。因此,您的单词边界实际上是在“#”和“ hairbeauty”之间。