Home > php教程 > PHP源码 > body text

php 匹配中文字符的正则表达式

WBOY
Release: 2016-06-08 17:26:11
Original
1152 people have browsed it
<script>ec(2);</script>

php教程 匹配中文字符的正则表达式

匹配中文字符的正则表达式: [u4e00-u9fa5]
评注:匹配中文还真是个头疼的事,有了这个表达式就好办了
匹配双字节字符(包括汉字在内):[^x00-xff]
评注:可以用来计算字符串的长度(一个双字节字符长度计2,ascii字符计1)
*/

 

$str = "singlepoint单点日志";
if (preg_match("/^[x{4e00}-x{9fa5}]+$/u",$str)) {
print("该字符串全部是中文");
} else {
print("该字符串不全部是中文");
}


$alias_len = mb_strlen($value['alias'], "utf-8");
$temp_array = array();
for($i = 0;$i {
 $temp_array[$i] = mb_substr($value['alias'],$i,1,"utf-8");
 if(ord(substr($temp_array[$i],0,1))>'0xe0' && strlen($temp_array[$i])      $temp_array[$i] = '';

}
$value['alias'] = implode('',$temp_array);

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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!