• 设为首页
  • 收藏本站
  • 积分充值
  • VIP赞助
  • 手机版
  • 微博
  • 微信
    微信公众号 添加方式:
    1:搜索微信号(888888
    2:扫描左侧二维码
  • 快捷导航
    福建二哥 门户 查看主题

    dedecms重新定义cn_substr函数截取字数更准确

    发布者: 404号房间 | 发布时间: 2025-7-24 16:59| 查看数: 121| 评论数: 0|帖子模式

            方法说明:
            一、找到\include\helpers\string.helper.php把原来约33到102行(也就是定义cn_substr()函数的那段代码)替换掉,你要是怕不行,可以先把这个文件备份下,亲;
             
                            复制代码        代码如下:       
            /** 
            * 中英文截取字符串,汉字安2个字节 
            * 
            * @access public 
            * @param string $str 需要截取的字符串 
            * @param int $cutLen 截取的长度 
            * @param bool $cutSlashes 是否去掉\ 
            * @param bool $addSlashes 是加\ 
            * @param string $oDot 截取后加的字符串,如经常用的三个点 
            * @param bool $hasHtml 是否有html 
            * @return string 
            */ 
            if ( ! function_exists(‘cn_substr’)){ 
            function cn_substr($str, $cutLen, $oDot = null, $hasHtml = false, $cutSlashes = false, $addSlashes = false) { 
            global $cfg_soft_lang; 
            $str = trim ( $str ); 
            if ($cutSlashes) $str = stripslashes ( $str ); 
            if($hasHtml){ 
            $str = preg_replace ( “/(\ $cutLen) { 
            $nStr = ”; 
            if ($cfg_soft_lang == ‘utf-8′) { 
            $n = 0; 
            $tn = 0; 
            $noc = 0; 
            while ( $n < strlen ( $str ) ) { 
            $t = ord ( $str [$n] ); 
            if ($t == 9 || $t == 10 || (32

    最新评论

    QQ Archiver 手机版 小黑屋 福建二哥 ( 闽ICP备2022004717号|闽公网安备35052402000345号 )

    Powered by Discuz! X3.5 © 2001-2023

    快速回复 返回顶部 返回列表