可以說我有不好的話數組:preg_match字符串中的數組項?
$badwords = array("one", "two", "three");
和隨機字符串:
$string = "some variable text";
如何創建這個循環:
if (one or more items from the $badwords array is found in $string)
echo "sorry bad word found";
else
echo "string contains no bad words";
例如:
如果$string = "one fine day" or "one fine day two of us did something"
,用戶應該看到對不起壞字發現的消息。
如果$string = "fine day"
,用戶應該看到字符串包含沒有不良詞的消息。我知道,你不能preg_match
從數組。任何建議?
$ string是百達一個隨機字符串,它的搜索查詢更具體的。所以如果訪問者輸入包含不好的單詞的查詢,他應該看不到任何結果,否則..那麼你明白了嗎? :) – DadaB 2012-04-27 22:00:35
和**是的,你可以'preg_match' **一個數組,你只需要先崩潰它。檢查我給出的答案。 – 2012-04-28 00:29:12