php 区分中文,英文,中英混合

 1             $str1="是你";

 2             $strA = trim($str1);

 3             $lenA = strlen($strA);

 4             $lenB = mb_strlen($strA,"utf-8");

 5             if($lenA===$lenB){

 6                 echo "英文";

 7             }else{

 8                 if($lenA % $lenB == 0){

 9                     echo "中文"; 

10                   }else{

11                     echo  "中英";

12                   }

13             }

 

你可能感兴趣的:(PHP)