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

WBOY
Release: 2016-07-21 15:03:42
Original
847 people have browsed it

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]{...
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 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!