How to determine whether a string is Chinese or English in php

藏色散人
Release: 2023-03-09 16:20:01
Original
3367 people have browsed it

php method to determine whether a string is Chinese or English: 1. Determine whether it is English through "preg_match("/^[^\x80-\xff]...);"; 2. Through "preg_match ("/^[".chr(0xa1)."-".chr..."]" to determine whether it is Chinese.

How to determine whether a string is Chinese or English in php

The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer

PHP determines whether a string is Chinese or English

function is_chinese($s){
        $allen = preg_match("/^[^\x80-\xff]+$/", $s);   //判断是否是英文
        $allcn = preg_match("/^[".chr(0xa1)."-".chr(0xff)."]+$/",$s);  //判断是否是中文
        if($allen){  
              return 'allen';  
        }else{  
              if($allcn){  
                   return 'allcn';  
              }else{  
                   return 'encn';  
              }  
        } 
   }
Copy after login

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to determine whether a string is Chinese or English in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
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