Home >Backend Development >PHP Tutorial >PHP function to determine whether a string is English or Chinese

PHP function to determine whether a string is English or Chinese

WBOY
WBOYOriginal
2016-07-25 08:58:351554browse
  1. static function ischinese($s){

  2. $allen = preg_match("/^[^/x80-/xff]+ $/", $s); //Determine whether it is English

  3. $allcn = preg_match("/^[".chr(0xa1)."-".chr(0xff)."]+$/",$s) ; //Determine whether it is Chinese
  4. if($allen){
  5. return 'allen';
  6. }else{
  7. if($allcn){
  8. return 'allcn';
  9. }else{
  10. return 'encn';
  11. }
  12. }
  13. }
  14. ?> //by bbs.it-home.org

Copy code


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