Home > Backend Development > PHP Tutorial > php中判断字符串是否全是中文或含有中文的实现代码_php技巧

php中判断字符串是否全是中文或含有中文的实现代码_php技巧

PHP中文网
Release: 2016-05-17 09:15:30
Original
1636 people have browsed it

php中判断字符串是否全是中文或含有中文的实现代码_php技巧

一,判断全是中文

 代码如下:

$str="'324是"; 
if(!eregi("[^\x80-\xff]","$str")){ 
echo "全是中文"; 
}else{ 
echo "不是"; 
}
Copy after login


二,判断含有中文

代码如下:

$str = "中文"; 
if (preg_match("/[\x7f-\xff]/", $str)) { 
echo "含有中文"; 
}else{ 
echo "没有中文"; 
}
Copy after login


$pattern = '/[^\x00-\x80]/'; 
if(preg_match($pattern,$str)){ 
echo "含有中文"; 
}else{ 
echo "没有中文"; 
}
Copy after login


我这几种方法都是在utf-8下面测试的,别的编码下没有测试过。

以上就是php中判断字符串是否全是中文或含有中文的实现代码_php技巧的内容,更多相关内容请关注PHP中文网(www.php.cn)!


Related labels:
source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template