PHP无乱码截取中文字符串
来源:互联网 发布:淘宝卖家寄错地址 编辑:程序博客网 时间:2024/05/29 14:24
function msubstr($str, $start=0, $length, $charset="utf-8", $suffix=true)
{
if(function_exists("mb_substrs")){
$slice = mb_substr($str, $start, $length, $charset);
}elseif(function_exists('iconv_substr')) {
$slice = iconv_substr($str,$start,$length,$charset);
}else{
$re['utf-8'] = "/[\x01-\x7f]|[\xc2-\xdf][\x80-\xbf]|[\xe0-\xef][\x80-\xbf]{2}|[\xf0-\xff][\x80-\xbf]{3}/";
$re['gb2312'] = "/[\x01-\x7f]|[\xb0-\xf7][\xa0-\xfe]/";
$re['gbk'] = "/[\x01-\x7f]|[\x81-\xfe][\x40-\xfe]/";
$re['big5'] = "/[\x01-\x7f]|[\x81-\xfe]([\x40-\x7e]|\xa1-\xfe])/";
preg_match_all($re[$charset], $str, $match);
$slice = join("",array_slice($match[0], $start, $length));
}
if($suffix) return $slice."…";
return $slice;
}
{
if(function_exists("mb_substrs")){
$slice = mb_substr($str, $start, $length, $charset);
}elseif(function_exists('iconv_substr')) {
$slice = iconv_substr($str,$start,$length,$charset);
}else{
$re['utf-8'] = "/[\x01-\x7f]|[\xc2-\xdf][\x80-\xbf]|[\xe0-\xef][\x80-\xbf]{2}|[\xf0-\xff][\x80-\xbf]{3}/";
$re['gb2312'] = "/[\x01-\x7f]|[\xb0-\xf7][\xa0-\xfe]/";
$re['gbk'] = "/[\x01-\x7f]|[\x81-\xfe][\x40-\xfe]/";
$re['big5'] = "/[\x01-\x7f]|[\x81-\xfe]([\x40-\x7e]|\xa1-\xfe])/";
preg_match_all($re[$charset], $str, $match);
$slice = join("",array_slice($match[0], $start, $length));
}
if($suffix) return $slice."…";
return $slice;
}
0 0
- PHP无乱码截取中文字符串
- php截取中文无乱码
- PHP截取中文无乱码
- php中文截取无乱码
- PHP 中文无乱码截取
- mrytsr PHP截取中文字符串,无乱码,基于正则
- PHP字符串截取,无乱码
- php 中文字符串截取乱码
- PHP 中文字符串截取无乱码的方法以及php汉字截取函数_preg_split()
- php截取中文字符串长度的mb_substr()、mb_strcut()函数,自定义实现中文字符串无乱码方法
- 中文字符串截取无乱码方法定义
- PHP截取中文字符无乱码 mb_substr()
- 中文截取无乱码的PHP
- 中文截取无乱码的PHP方法
- PHP实现中文字串截取无乱码
- PHP字符串截取(无乱码)
- 中文截取无乱码
- php截取中文字符串时乱码问题
- Android Context简介
- 【马仔创业记】一只猴子的创业独白(1)
- kibana链接不上elasticseacher配置!!配置elasticseacher可以跨域访问!(xjh 测过)
- 2016SDAU课程练习三1011 Problem K
- linux的启动过程
- PHP无乱码截取中文字符串
- C H A P T E R 2 9 Building a Web Services Client 29章构建一个Web Services 客户端
- Stack的三种含义
- java Date型时间比较大小
- Java版的Redis
- ?
- JSP页面EL表达式不起效果
- soot代码分析框架的基础知识(二)
- listview中android:descendantFocusability子控件和整个Item获取焦点事件处理