Using PHP stripos() in Logical Filtering -
how can use stripos filter out unwanted word existing on itself. how twist code below search 'won
' in grammar not return true, since 'wonderful
' word itself.
$grammar = 'it wonderful day'; $bad_word = 'won'; $res = stripos($grammar, $bad_word,0); if($res === true){ echo 'bad word present'; }else{ echo 'no bad word'; } //result 'bad word present'
use preg_match
$grammar = 'it wonderful day'; $bad_word = 'won'; $pattern = "/ +" . $bad_word . " +/i"; // works 1 ore more spaces around bad word, /i means it's not case sensitive $res = preg_match($pattern, $grammar); // returns 1 if pattern has been found if($res == 1){ echo 'bad word present'; } else{ echo 'no bad word'; }
Comments
Post a Comment