Hello, I want to do something if my sentence include one of the words in this array, How to do that ? $sentence = "I dont give a shit"; $values = array("lick","shit","pussy","horny"); PHP: Thanks...
$sentence = "I dont give a shit"; $values = array("lick","shit","pussy","horny"); $found = 0; foreach($values as $val) { if(strpos($sentence,$val) != -1) { //found one $found = 1; } } // if it found one or more $found = 1 else $found = 0 PHP: this is just one way.. there are more ways to do this..
Personally I'd use a boundary based regex of the words function to_regex($string) { return '%\b'.preg_quote($string).'\b%i'; } $filter = array_map('to_regex', $values); foreach($filter as $val) { if(preg_match($val, $sentence) { //Do whatever here } } PHP: EDIT: Also, this is case insensitive Also, use google for this kind of thing, they're out there in the thousands http://www.google.com/search?hl=en&q=php+word+filter&aq=f&oq=&aqi=g1