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

PHP截取utf字符

WBOY
Release: 2016-06-06 19:58:28
Original
1026 people have browsed it

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 来截取中文,会导致乱码,是因为编码问题,中文每个字会占用三个字符,所以进行截取的同时,需要判断再进行截取,避免乱码问题。

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