php - How to Use Stristr in array Variable -
i need check words in array variable, need this:
$banned = array('word1','word2','word3','word4'); if (stristr($title, $banned) !== false) { //$title contains banned word }else{ //$title not contains word of $banned variable array }
<?php $banned = array('word1','word2','word3','word4'); $hit = false; foreach ($banned $banned_item) { if (strpos($title, $banned_item) !== false) { $hit = true; break; } } if ($hit) { // $title contains banned word } else { //$title not contains word of $banned variable array }
_
************** update1 **************
the code above case-sensitive, if want code case-insensitive, change:
if (strpos($title, $banned_item) !== false)
to:
if (stristr($title, $banned_item) !== false)
Comments
Post a Comment