php实现过滤字符串中的中文和数字实例,_PHP教程

WBOY
Release: 2016-07-13 09:45:46
Original
1016 people have browsed it

php实现过滤字符串中的中文和数字实例,

本文实例讲述了php实现过滤字符串中的中文和数字。分享给大家供大家参考。具体实现方法如下:

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; $i<$strlen; $i++) {
   $str=substr($string, $i, 1);
   $str1=trim($str);
   if( ord($str)>0xA0 ){
   $tmpstr.= substr($string, $i, $codelength);
   $i = $i+$codelength-1;
   }
  }
 return $tmpstr;
}

Copy after login

希望本文所述对大家的php程序设计有所帮助。

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/1039199.htmlTechArticlephp实现过滤字符串中的中文和数字实例, 本文实例讲述了php实现过滤字符串中的中文和数字。分享给大家供大家参考。具体实现方法如下:...
Related labels:
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!