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

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -