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
Release: 2016-07-25 08:58:35
Original
1545 people have browsed it
  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


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