Home >Backend Development >PHP Tutorial >如何判断包含某个中文字?

如何判断包含某个中文字?

WBOY
WBOYOriginal
2016-06-20 12:53:53853browse

$str=array("西瓜","苹果","香蕉")$str_long="西瓜很大颗";


回复讨论(解决方案)

哪个判断哪个?

$str_long句子里有没有包含阵列里面的字

$arr=array("西瓜","苹果","香蕉");$str_long="西瓜很大颗";foreach($arr as $k=>$v){	if(strpos($str_long,$v)!==false){		$exists[]=$v;	}}echo "<pre class="brush:php;toolbar:false">";print_r($exists);echo "
";/*Array(    [0] => 西瓜)*/

$str=array("西瓜","苹果","香蕉");$str_long="西瓜很大颗";if(strlen($str_long) != strlen(str_replace($str, '', $str_long))) {  echo '存在';}

$count = 0;
str_replace($str, '', $str_long, $count);
if( $count > 0 ){
    //echo "存在";
}

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