可以说我有一系列不好的词:
$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
从数组中。有什么建议吗?