Check if a string contain multiple specific words

后端 未结 6 1202
独厮守ぢ
独厮守ぢ 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:22

    if(preg_match('[bad|naughty]', $data) === true) { }

    The above is not quite correct.

    "preg_match() returns 1 if the pattern matches given subject, 0 if it does not, or FALSE if an error occurred."

    So it should be just:

    if(preg_match('[bad|naughty]', $data)) { }
    

提交回复
热议问题