Home >php教程 >php手册 >PHP判断是中文还是英文,

PHP判断是中文还是英文,

WBOY
WBOYOriginal
2016-06-13 09:05:111422browse

PHP判断是中文还是英文,

<span>static</span> <span>function</span> ischinese(<span>$s</span><span>){
 
        </span><span>$allen</span> = <span>preg_match</span>("/^[^/x80-/xff]+$/", <span>$s</span>);   <span>//</span><span>判断是否是英文</span>
        <span>$allcn</span> = <span>preg_match</span>("/^[".<span>chr</span>(0xa1)."-".<span>chr</span>(0xff)."]+$/",<span>$s</span>);  <span>//</span><span>判断是否是中文</span>
        <span>if</span>(<span>$allen</span><span>){  
              </span><span>return</span> 'allen'<span>;  
        }</span><span>else</span><span>{  
              </span><span>if</span>(<span>$allcn</span><span>){  
                   </span><span>return</span> 'allcn'<span>;  
              }</span><span>else</span><span>{  
                   </span><span>return</span> 'encn'<span>;  
              }  
        }  
               
   }</span>

 

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