Home >php教程 >php手册 >PHP截取utf字符

PHP截取utf字符

WBOY
WBOYOriginal
2016-06-06 19:58:281055browse

php的 substr 来截取中文,会导致乱码,是因为编码问题,中文每个字会占用三个字符,所以进行截取的同时,需要判断再进行截取,避免乱码问题。 //UTF截取中文function utf_substr($str,$len){for($i=0;$i$len;$i++){$temp_str=substr($str,0,1);if(ord($temp

php的 substr 来截取中文,会导致乱码,是因为编码问题,中文每个字会占用三个字符,所以进行截取的同时,需要判断再进行截取,避免乱码问题。

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