Home > php教程 > php手册 > php中文字符截取防乱码

php中文字符截取防乱码

WBOY
Release: 2016-06-13 12:29:48
Original
922 people have browsed it

先看段代码 

复制代码 代码如下:



$len = 15;          

$str = "这个新闻或是文章的标题很长,需要只显示前面一些字,后面用...来代替";       
echo strlen($str)?>  

 

chr(0)相关知识:
null是什么都没有,而chr(0)的值是0。表示成16进制是0x00,表示成二进制是00000000 
虽然chr(0)不会显示出什么,但是他是一个字符。 


淡水ps:
如果是UTF-8,UTF-8中的汉字是3个字节的,截取的长度尽量去3的倍数,以避免乱码的产生
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