Home >Backend Development >PHP Tutorial >使用php统计字符串中中英文字符的个数_php技巧

使用php统计字符串中中英文字符的个数_php技巧

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-05-17 08:59:261199browse
复制代码 代码如下:

echo $str = "43fdf测试fdsfadaf43543543职工问防盗锁防盗锁5345gfdgd";
preg_match_all("/[0-9]{1}/",$str,$arrNum);
preg_match_all("/[a-zA-Z]{1}/",$str,$arrAl);
preg_match_all("/([/x{4e00}-/x{9fa5}]){1}/u",$str,$arrCh);
echo "
";<br>echo "数字个数:".count($arrNum[0])."<br>";<br>echo "字母个数:".count($arrAl[0])."<br>";<br>echo "中文个数:".count($arrCh[0]);<br>?><br>
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