Home  >  Article  >  Backend Development  >  Solution to php intercepting utf-8 Chinese string garbled characters_PHP tutorial

Solution to php intercepting utf-8 Chinese string garbled characters_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:40:15760browse

复制代码 代码如下:

function utf8_substr($str,$len)
{
  for($i=0;$i<$len;$i++)
  {
    $temp_str=substr($str,0,1);
    if(ord($temp_str) > 127){
      $i++;
    if($i<$len){
      $new_str[]=substr($str,0,3);
      $str=substr($str,3);
      }
    }else {
    $new_str[]=substr($str,0,1);
    $str=substr($str,1);
    }
  }
  return join($new_str);
}

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/321426.htmlTechArticle复制代码 代码如下: function utf8_substr($str,$len) { for($i=0;$i$len;$i++) { $temp_str=substr($str,0,1); if(ord($temp_str) 127){ $i++; if($i$len){ $new_str[]=substr($str,0,...
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