Home>Article>Backend Development> PHP determines whether a string contains an element value in an array

PHP determines whether a string contains an element value in an array

不言
不言 Original
2018-04-19 10:15:50 5573browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn