Home > Backend Development > PHP Tutorial > php截取utf-8中文字符串乱码的解决方法_php技巧

php截取utf-8中文字符串乱码的解决方法_php技巧

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-05-17 09:26:50
Original
881 people have browsed it
复制代码 代码如下:

function utf8_substr($str,$len)
{
  for($i=0;$i  {
    $temp_str=substr($str,0,1);
    if(ord($temp_str) > 127){
      $i++;
    if($i      $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);
}
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template