网络中常常用到,比如,超出的长度范围,用"..."来省略表示,这个函数完全能够胜任。
mb_strimwidth函数在PHP 4 >= 4.0.6, PHP 5中含有,用法
string mb_strimwidth (string $str , int $start , int $width [, string$trimmarker [, string$encoding ]] )
str
The string being decoded. //要进行截取省略的字符,比如'Hello world!~'.
The start position offset. Number of characters from the beginning of string. (First character is 0) //开始截取的字符位置
The width of the desired trim. //截取几个字符??
A string that is added to the end of string when string is truncated. //截取后,添加什么字符
encoding参数为字符编码。如果省略,则使用内部字符编码。
实例
<?php echo mb_strimwidth("Hello World", 0, 10, "...",'uft8');//当使用uft8编码的中文时,加上uft8可以防止中文截取部分乱码问题 //官方是这么写的:echo mb_strimwidth("Hello World", 0, 10, "..."); // outputs Hello W... ?>
很简单吧??呵呵