使用php統計字符串中中英文字符的個數


<?php
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 "<pre>";
echo "數字個數:".count($arrNum[0])."<br/>";
echo "字母個數:".count($arrAl[0])."<br/>";
echo "中文個數:".count($arrCh[0]);
?>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章