Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/api/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在文章中搜索精确匹配的关键字?我发现的标准正则表达式不';行不通_Php_Regex_Wordpress - Fatal编程技术网

Php 在文章中搜索精确匹配的关键字?我发现的标准正则表达式不';行不通

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?这意味着它

我正在处理wordpress的文章,搜索某些关键词,比如“性”,但不是“性”

我试过了

$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~
可以正常工作。谢谢你指出这一点。谢谢你指出这一点。谢谢你指出这一点。谢谢你指出这一点。