Check if a string contain multiple specific words

后端 未结 6 1224
独厮守ぢ
独厮守ぢ 2020-12-04 16:46

How to check, if a string contain multiple specific words?

I can check single words using following code:

$data = "text text text text text text t         


        
6条回答
  •  日久生厌
    2020-12-04 17:05

    You can't do something like this:

    if (strpos($data, 'bad || naughty') !== false) {
    

    instead, you can use regex:

    if(preg_match("/(bad|naughty|other)/i", $data)){
     //one of these string found
    }
    

提交回复
热议问题