Home  >  Article  >  Backend Development  >  Use PHP to count the number of Chinese and English characters in a string_PHP Tutorial

Use PHP to count the number of Chinese and English characters in a string_PHP Tutorial

WBOY
WBOYOriginal
2016-07-21 15:03:42893browse

Copy code The code is as follows:

echo $str = "43fdf test fdsfadaf43543543 employee asked about anti-theft lock anti-theft lock 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 "
 ";
echo "Number of digits:".count($arrNum[0])."
";
echo "Number of letters:".count($arrAl[0]) ."
";
echo "Chinese number:".count($arrCh[0]);
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/327831.htmlTechArticleCopy the code code as follows: ?php echo $str = "43fdf test fdsfadaf43543543 employee asked about anti-theft lock anti-theft lock 5345gfdgd"; preg_match_all("/[0-9]{1}/",$str,$arrNum); preg_match_all("/[a-zA-Z]{...
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