Efficient way to test string for certain words

前端 未结 6 1757
一整个雨季
一整个雨季 2020-12-17 08:03

I have a bunch of banned words and want to check if string A contains any of these words.

For example:

$banned_words = \"dog cat horse bird mouse mon         


        
6条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-17 08:35

    $badwords = array('dog','cat','horse','bird','mouse','monkey');
    $content= "The quick brown fox jumped over the lazy dog";
    $content = str_replace($badwords, 'has_badwords' $content);
    if (strpos($content, 'has_badwords') !== false) {
        echo 'true';
    }
    

提交回复
热议问题