php中中文截取函数mb_substr()详细
一、中文截取:mb_substr()
mb_substr( $str, $start, $length, $encoding )
$str,需要截断的字符串
$start,截断开始处,起始处为0
$length,要截取的字数
$encoding,网页编码,如utf-8,GB2312,GBK
实例:
<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onclick="doCopy('copy6947')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy6947><?http://www.111cn.net';echo mb_substr($str,0,5,'utf-8');//截取头5个字,假定此代码所在php文件的编码为utf-8
?>
结果显示:电影618
二、获取中文长度:mb_strlen()
mb_strlen( $str, $encoding )
$str,要计算长度的字符串
$encoding,网页编码,如utf-8,GB2312,GBK
实例:
<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onclick="doCopy('copy8178')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy8178><?php$str='电影618:http://www.111cn.net';
echo mb_strlen($str,'utf-8');//假定此代码所在php文件的编码为utf-8
?>
结果显示:29
您可能感兴趣的文章:
php中文截取字符串mb_substr的用法
php截取中文字符串的二个函数(iconv_substr和mb_substr)
php如何截取字符串后四位
php中文字符截取函数(自用)
php中文截取字符串函数(很好用)
php截断字符串函数mb_substr()范例
php函数substr(),mb_substr()及mb_strcut的区别分析
php中中文截取函数mb_substr()详细
php无乱码切割中文字符
php中文字符串截取方法