Use php to count the numbers of Chinese and English characters in a string _ PHP Tutorial

Source: Internet
Author: User
Use php to count the number of Chinese and English characters in the string. Copy the code as follows :? Phpecho $ str43fdf test fdsfadaf43543543 employee asked anti-Leech 5345 gfdgd; preg_match_all ([0-9] {1}, $ str, $ arrNum); preg_match_all ([a-zA-Z] { The code is as follows:


Echo $ str = "43fdf test fdsfadaf43543543 the employee asked about the anti-Leech 5345 gfdgd ";
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:". count ($ arrNum [0])."
";
Echo "letter count:". count ($ arrAl [0])."
";
Echo "number of Chinese characters:". count ($ arrCh [0]);
?>

The http://www.bkjia.com/PHPjc/327831.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/327831.htmlTechArticle code is as follows :? Php echo $ str = "43fdf test fdsfadaf43543543 employee asked anti-Leech 5345 gfdgd"; preg_match_all ("/[0-9] {1}/", $ str, $ arrNum ); preg_match_all ("/[a-zA-Z] {...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.