Php 在文章中搜索精确匹配的关键字?我发现的标准正则表达式不';行不通
我正在处理wordpress的文章,搜索某些关键词,比如“性”,但不是“性” 我试过了Php 在文章中搜索精确匹配的关键字?我发现的标准正则表达式不';行不通,php,regex,wordpress,Php,Regex,Wordpress,我正在处理wordpress的文章,搜索某些关键词,比如“性”,但不是“性” 我试过了 $string = "Testing by placing the word at the end sex. More words here."; if ( preg_match("/\sex\b/i", strtolower($string) ) ) {} 及 但两者都返回false 显然,在一篇文章中,这个词可以在开头、结尾、标点附近等等。我怎么解释呢?你只缺少一个字符-注意性爱之后的\b?这意味着它
$string = "Testing by placing the word at the end sex. More words here.";
if ( preg_match("/\sex\b/i", strtolower($string) ) ) {}
及
但两者都返回false
显然,在一篇文章中,这个词可以在开头、结尾、标点附近等等。我怎么解释呢?你只缺少一个字符-注意性爱之后的
\b
?这意味着它是一个词的边界。在sex
之前还需要另一个,而不是\s
——这意味着空白
$string = "Testing by placing the word at the end sex. More words here.";
if ( preg_match("~\bsex\b~", strtolower($string) ) ) {}
^---- extra b here
你只缺少了一个字符-注意性爱后的
\b
?这意味着它是一个词的边界。在sex
之前还需要另一个,而不是\s
——这意味着空白
$string = "Testing by placing the word at the end sex. More words here.";
if ( preg_match("~\bsex\b~", strtolower($string) ) ) {}
^---- extra b here
你只缺少了一个字符-注意性爱后的
\b
?这意味着它是一个词的边界。在sex
之前还需要另一个,而不是\s
——这意味着空白
$string = "Testing by placing the word at the end sex. More words here.";
if ( preg_match("~\bsex\b~", strtolower($string) ) ) {}
^---- extra b here
你只缺少了一个字符-注意性爱后的
\b
?这意味着它是一个词的边界。在sex
之前还需要另一个,而不是\s
——这意味着空白
$string = "Testing by placing the word at the end sex. More words here.";
if ( preg_match("~\bsex\b~", strtolower($string) ) ) {}
^---- extra b here
您丢失了字母“b”
~\bsex\b~
您丢失了字母“b”~\bsex\b~
您丢失了字母“b”~\bsex\b~
您丢失了字母“b”~\bsex\b~
可以正常工作。谢谢你指出这一点。谢谢你指出这一点。谢谢你指出这一点。谢谢你指出这一点。