php - Matching a list of words with a sentence -
i have list of "bad" words having around 450 words in it.
i'm trying check sentence with
<?php $sentence = "a quick brown fox jumps on lazy dog"; foreach($words $word) { $check = strstr($sentence,$word); if(!empty($check)) return false; } return true; ?>
is there faster , better approach this?
you try using preg_split
, array_intersect
<?php $sentence = "a quick brown fox jumps on lazy dog"; $sntce_wrds = preg_split('/\s+/', $sentence); return count(array_intersect($sntnce_words, $words)) > 0;
Comments
Post a Comment