2
我得到這個錯誤...警告:的preg_match()[function.preg匹配]:未知的修飾
警告:的preg_match()[function.preg匹配]:在未知的修飾詞 '1' C:\ path-to-plugin.php on line 147
當我運行關鍵字「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);
}
我假設我需要清理關鍵字來轉義「/」字符(可能更多)。我希望你有任何建議,在通過preg_match運行之前必須對字符串進行清理。
UPDATE: 這似乎是由於工作,以泰國:
function my_get_kw_in_content($theKeyword, $theContent)
{
$theKeyword = preg_quote($theKeyword, '/');
return preg_match('/\b' . $theKeyword . '\b/i', $theContent);
}
泰國人,我用你的答案更新了我的問題。它似乎在爲我工作。你能檢查我的更新以確保我正確地實施你的答案嗎? –
是的,它是正確的。 :) – Thai