I'm getting this error...
Warning: preg_match() [function.preg-match]: Unknown modifier '1' in C:\path-to-plugin.php on line 147
When I run the keyword "Test $2/1 test+word!" through the function below
function my_get_kw_in_content($theKeyword, $theContent)
{
//ERROR OCCURS NEXT LINE
return preg_match('/\b' . $theKeyword . '\b/i', $theContent);
}
I'm assuming that I need to sanitize the keyword to escape the "/" character (and possibly more). I'd appreciate any suggestions you have to sanitize the string before running it through the preg_match.
UPDATE: This appears to work thanks to Thai:
function my_get_kw_in_content($theKeyword, $theContent)
{
$theKeyword = preg_quote($theKeyword, '/');
return preg_match('/\b'开发者_运维问答 . $theKeyword . '\b/i', $theContent);
}
Use preg_quote
to quote regular expression characters.
Like this:
preg_quote($theKeyword, '/');
Where '/'
is the delimiter in your regular expression.
精彩评论