Efficient way to test string for certain words

前端 未结 6 1763
一整个雨季
一整个雨季 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:52

    Wouldn't it be better if the $banned_w would be an array?

    Then you could explode() the string you want to check for banned words, then for every exploded piece use in_array() to check if it's a banned word.

    Edit: You could use: similar_text for the comparisons, if one modifies the bad word a bit.

提交回复
热议问题