我收到这个错误......
警告:preg_match()[function.preg-match]:第147行的C:\ path-to-plugin.php中的未知修饰符'1'
当我运行关键字"Test $ 2/1 test + word!"时 通过下面的功能
function my_get_kw_in_content($theKeyword, $theContent)
{
//ERROR OCCURS NEXT LINE
return preg_match('/\b' . $theKeyword . '\b/i', $theContent);
}
Run Code Online (Sandbox Code Playgroud)
我假设我需要清理关键字以逃避"/"字符(可能更多).我很感激你在通过preg_match运行它之前要清理字符串的任何建议.
更新:这似乎是由于泰国工作:
function my_get_kw_in_content($theKeyword, $theContent)
{
$theKeyword = preg_quote($theKeyword, '/');
return preg_match('/\b' . $theKeyword . '\b/i', $theContent);
}
Run Code Online (Sandbox Code Playgroud)
使用preg_quote引用正则表达式字符.
像这样:
preg_quote($theKeyword, '/');
Run Code Online (Sandbox Code Playgroud)
'/'正则表达式中的分隔符在哪里.
| 归档时间: |
|
| 查看次数: |
3343 次 |
| 最近记录: |