ThinkPHP\Common\extend.php 中管理前台模版的截取{$vons.title|msubstr=0,26}

原始的代码是无法使用截取支持….  由于涉及到只有汉字检测最为准确

需要加入代码让他正常的分页截取之后加入…

function msubstr($str, $start=0, $length, $charset=”utf-8″, $suffix=true)
{
if(strlen($str)/3>$length){
if(function_exists(“mb_substr”)){
return mb_substr($str, $start, $length, $charset).’…’;
}
elseif(function_exists(‘iconv_substr’)) {
return iconv_substr($str,$start,$length,$charset).’…’;
}
$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;
}else{
return $slice;
}
}
return $str;
}

thinkphp前台模版字符串截取的更多相关文章

  1. thinkPHP内置字符串截取msubstr函数用法详解

    作者:陈达辉 字体:[增加 减小] 类型:转载 时间:2016-11-15 我要评论 这篇文章主要介绍了thinkPHP内置字符串截取函数用法,结合实例形式分析了thinkPHP内置的字符串截取函数功 ...

  2. Thinkphp 3.2中字符串截取

    将此方法放到Thinkphp/Common/function.php里/* * 字符串截取函数 * 大白驴 * 2016-11-29 qq 675835721 * */function msubstr ...

  3. ThinkPHP+Smarty模板中截取包含中英文混合的字符串乱码的解决方案

    好几天没写博客了,其实有好多需要总结的,因为最近一直在忙着做项目,但是困惑了几天的Smarty模板中截取包含中英文混合的字符串乱码的问题,终于解决了,所以记录下来,需要的朋友看一下: 出现乱码的原因: ...

  4. ThinkPHP 模板substr的截取字符串函数

    ThinkPHP 模板substr的截取字符串函数在Common/function.php加上以下代码 /** ** 截取中文字符串 **/ function msubstr($str, $start ...

  5. Thinkphp 模板中直接对数据处理 模板中使用函数 中文字符串截取

    1.Thinkphp 模板中直接对数据处理:{$data.name|substr=0,3} 2.中文字符串截取函数:mb_substr=0,14,'utf-8' 3.中文字符串统计:iconv_str ...

  6. 【freemaker】之文本,html文本,去除空格,字母大小写,循环数组,字符串截取,map取值,遍历map

    测试代码 @Test public void test06(){ try { root.put("emp", "<span color='red'>你好张三& ...

  7. MySQL字符串函数substring:字符串截取

    MySQL 字符串截取函数:left(), right(), substring(), substring_index().还有 mid(), substr().其中,mid(), substr() ...

  8. Python第一天 - list\字符串截取

    (一)list截取L =['Adam', 'Lisa', 'Bart'] print(L[0:3]) ======>['Adam'(idnex:0), 'Lisa'(index:1), 'Bar ...

  9. Shell脚本8种字符串截取方法总结

    Linux 的字符串截取很有用.有八种方法. 假设有变量 var=http://www.aaa.com/123.htm. 1. # 号截取,删除左边字符,保留右边字符. 代码如下: echo ${va ...

随机推荐

  1. 【struts2】<s:url>标签

    <s:url>标签一般和超链接 <a>一起使用,用于带多个参数. <a href=" <s:url action=""> < ...

  2. MySQL 错误1418

    创建function的时候报如下错误: Error Code : This function has none of DETERMINISTIC, NO SQL, or READS SQL DATA ...

  3. 跟我学SharePoint2013视频培训课程——设置列表名称、描述、导航等基本信息(12)

    课程简介 第12天,怎样在SharePoint 2013设置列表名称.描述.导航等基本信息. 视频 SharePoint 2013 交流群 41032413

  4. SharePoint 2013 Backup Farm Automatically With a Powershell and Windows Task Schedule

    In this post,I will show you SharePoint 2013 How to Backup Farm Automatically with a PowerShell and ...

  5. stm8 时钟输出引脚

    CLK_CCO引脚是STM8的时钟输出引脚,若设置该脚输出主时钟Fmaster,时钟输出寄存器可以进行如下操作 CLK->CCOR=0X19;

  6. python标准库介绍——30 code 模块详解

    ==code 模块== ``code`` 模块提供了一些用于模拟标准交互解释器行为的函数. ``compile_command`` 与内建 ``compile`` 函数行为相似, 但它会通过测试来保证 ...

  7. CentOS 7 重装mysql编译过程报错解决方法

    错误记录: [ 82%] Building C object libmysql/CMakeFiles/clientlib.dir/__/sql-common/client.c.o/usr/local/ ...

  8. GCD 实现生产-消费 模式

    #import "ViewController.h" @interface ViewController (){ } @property (nonatomic,strong) di ...

  9. opencv之haar特征+AdaBoos分类器算法流程(三)

    watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/ ...

  10. 【Unity】11.4 车轮碰撞体(Wheel Collider)

    分类:Unity.C#.VS2015 创建日期:2016-05-02 一.简介 车轮碰撞体 (Wheel Collider)专门用于创建汽车或其他移动交通工具. 车轮碰撞体是一种针对地面车辆的特殊碰撞 ...