Home > php教程 > PHP源码 > 过滤字符串中的中文和数字

过滤字符串中的中文和数字

PHP中文网
Release: 2016-05-25 17:09:46
Original
1264 people have browsed it

过滤字符串中的中文和数字

function getChinese($string,$encode="GBK") {
       switch($encode){
            case "GBK" :$codelength=2;break;
       case "GB2312" :$codelength=3;break;
       case "UTF-8" :$codelength=3;break;
           case "UTF-16" :$codelength=4;break;
 
       }
       $tmpstr = '';
       $arr = array(1,2,3,4,5,6,7,8,9,0);
       $strlen = strlen($string);
       for($i=0; $i0xA0 ){
            $tmpstr.= substr($string, $i, $codelength);
            $i = $i+$codelength-1;
            }
 
}
    return $tmpstr;
}
Copy after login

                   

以上就是过滤字符串中的中文和数字的内容,更多相关内容请关注PHP中文网(www.php.cn)!

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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template