Home>Article>Backend Development> PHP determines whether a string contains an element value in an array
The content of this article is about PHP's judgment that a string contains an element value in an array. It has a certain reference value. Now I share it with you. Friends in need can refer to it
$arr=array('安卓','过滤','小程序'); //如果是字符串,需要先打散成数组再判断$str='安卓手机'; foreach($arr as $key){ if(strstr($str,$key)) { //列表中包含过滤的新内容.如果str来自其它网页,需要保证编码相同. echo 0; exit; }else{ echo 1; exit; } }
Related recommendations:
php method to determine whether the json format is correct
The above is the detailed content of PHP determines whether a string contains an element value in an array. For more information, please follow other related articles on the PHP Chinese website!