博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
TP之msubstr()
阅读量:6972 次
发布时间:2019-06-27

本文共 746 字,大约阅读时间需要 2 分钟。

hot3.png

function msubstr($str, $start=0, $length, $charset="utf-8", $suffix=true) {

        if(function_exists("mb_substr"))

            $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));

        }

        return $suffix ? $slice.'...' : $slice;

    }

转载于:https://my.oschina.net/guomingliang/blog/313127

你可能感兴趣的文章
一位10年Java工作经验的架构师聊Java和工作经验
查看>>
英文词频统计预备,组合数据类型练习
查看>>
完成个人中心—导航标签
查看>>
UVA10603 Fill
查看>>
POJ NOI MATH-7652 乘积最大的拆分
查看>>
汉若塔问题算法程序
查看>>
解决Mysql ERROR 1045 (28000): Access denied for user 'root'@'localhost'问题
查看>>
ReOut
查看>>
如何使用SecureCRT连接vmware下ubuntu
查看>>
从源代码制作iDempiere Server安装软件(Ubuntu Desktop 12.04 LTS 64位)
查看>>
jQuery必知必熟基础知识
查看>>
本原串
查看>>
Android ble 蓝牙4.0 总结一
查看>>
三大方案解决了Intellij IDEA 2017/2018.1.5 输入法 不跟随
查看>>
WebApi系列~StringContent与FormUrlEncodedContent
查看>>
Lind.DDD.SSO单点登陆组件的使用(原创)
查看>>
图的创建——邻接表法
查看>>
OJ错误命令解释
查看>>
Javascript的匿名函数
查看>>
python-memcached学习笔记
查看>>