教程集 www.jiaochengji.com
教程集 >  脚本编程  >  php  >  正文 php截断字符串函数mb_substr()范例

php截断字符串函数mb_substr()范例

发布时间:2016-05-15   编辑:jiaochengji.com
本文介绍下,php中用于截断字符串的函数mb_substr,有需要的朋友,参考下吧。

介绍下php函数mb_substr。

函数 mb_substr( $str, $start, $length, $encoding )

参数说明:
$str,需要截断的字符串
$start,截断开始处
$length,长度(注意,这个跟mb_strimwidth不同,1就代表一个中文字符)
$encoding,编码,我设为 utf-8

例子,截断文章标题,控制在15个文字:
 

复制代码 代码示例:
<?php
echo mb_substr(get_the_title(), 0, 15,"utf-8");
//by www.jbxue.com
?>

您可能感兴趣的文章:
php中文截取字符串mb_substr的用法
php截断字符串函数mb_substr()范例
php中文字符截取函数(自用)
php截取中文字符串的二个函数(iconv_substr和mb_substr)
php中文字符串截取(mb_substr)实例
php如何截取字符串后四位
php中文字符串截取方法
php中文截取字符串函数(很好用)
php函数substr(),mb_substr()及mb_strcut的区别分析
php截取中文字符串(无乱码)方法

[关闭]
~ ~