mb_strimwidth 截取字符串长度,并用其他字符替换

来源:互联网 发布:虹港数据 idc机房 编辑:程序博客网 时间:2024/05/23 14:36

网络中常常用到,比如,超出的长度范围,用"..."来省略表示,这个函数完全能够胜任。

 

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!~'.

start

       The start position offset. Number of       characters from the beginning of string. (First character is 0)      //开始截取的字符位置

width

       The width of the desired trim.      //截取几个字符??

trimmarker

       A string that is added to the end of string        when string is truncated.      //截取后,添加什么字符

encoding

encoding参数为字符编码。如果省略,则使用内部字符编码。

 

实例

 <?phpecho mb_strimwidth("Hello World", 0, 10, "...",'uft8');//当使用uft8编码的中文时,加上uft8可以防止中文截取部分乱码问题//官方是这么写的:echo mb_strimwidth("Hello World", 0, 10, "...");// outputs Hello W...?>


 


很简单吧??呵呵