WordPress企业主题定制/开发/优化

php利用mb_substr函数截取中文字串

首页 » PHP » php利用mb_substr函数截取中文字串

php利用mb_substr函数截取中文字串

php系统有自带中文字串截取函数,但是需要加载库php_mbstring.dll

1.php的版本必须>=4.0.6

2.php_mbstring的模块必须被装载->extension=php_mbstring.dll
liunx用户在编译php的时候加入-enable-mbstring参数就可以了

3.如果需要操作的字符是中文的话必须设置编码参数

mb_substr($string,5,1,"GB2312");

示例:

<?=mb_substr($rs->title,0,16,'utf-8')?>

从$rs->title中从0开始取16个字, utf-8格式

<?=mb_substr($rs->title,0,16,'gb2312')?>

从$rs->title中从0开始取16个字, gb2312格式

分类与标签:

PHP

,

相关项目

  • WordPress外贸企业主题

  • 最近更新

  • 热门标签