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

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

aspxgridview - Devexpress grid - header filter does not work if column is initially hidden -

c# - How to execute a particular part of code asynchronously in a class -