$key = [ '字', '串', ]; $string='字符串'; preg_match_all('#('.implode('|', $key).')#', $string, $wordsFound); $wordsFound = array_unique($wordsFound[0]); if(count($wordsFound) >= 1){ state(1,'存在'); }else{ state(0,'不存在'); } function state($s,$m){ echo json_encode(array('state'=>$s,'message'=>$m),true); }
PHP查询字符串是否包含,多个指定字符中的任意一个。