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

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -