最新活动:电脑PC端+手机端+微网站+自适应网页多模板选择-建站388元起价!!!
要源码
当前位置:主页 > 网站建设 > dedecms重新定义cn_substr函数截取字数更精准,织梦文

dedecms重新定义cn_substr函数截取字数更精准,织梦文

时间:2023-07-21 11:07:21 阅读: 文章分类: 网站建设 作者: 织梦网站员

导读:织梦文章织梦文章,dedecms的cn_substr()和cn_substr_utf8()截取的字符串ms不准,平时也用习惯cn_substr(),也不愿用什么cn_subst织梦模板免费下裁织梦模板。

织梦模板免费下裁织梦模板

,dedecms的cn_substr()和cn_substr_utf8()截取的字符串ms不准,平时也用习惯cn_substr(),也不愿用什么cn_substr_utf8()今天弄了下,现在还是比较准了。按照一个汉字2个字节调用就行了!

方法说明: 一、找到\include\helpers\string.helper.php把原来约33到102行(也就是定义cn_substr()函数的那段代码)替换掉,你要是怕不行,可以先把这个文件备份下,亲;

  • /**
  • *中英文截取字符串,汉字安2个字节
  • *
  • * @accesspublic
  • * @param string$str 需要截取的字符串
  • * @param int$cutLen 截取的长度
  • * @param bool $cutSlashes 是否去掉\
  • * @param bool $addSlashes 是加\
  • * @param string $oDot 截取后加的字符串,如经常用的三个点
  • * @param bool $hasHtml 是否有html
  • * @returnstring
  • */
  • 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 ( “/(\<[^\<]*\>|\r|\n|\s|\[.+?\])/is”, ‘ ‘, $str );
  • $str = htmlspecialchars ( $str );
  • }else{
  • $str = htmlspecialchars ( $str );
  • }
  • if ($cutLen && strlen ( $str ) > $cutLen) {
  • $nStr = ̶织梦cms模板1;;
  • 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 <= $t &&a手机模板dedemp; $t <= 126)) {
  • $tn = 1;
  • $n ++;
  • $noc ++;
  • } elseif (194 <= $t && $t <= 223) {
  • $tn = 2;
  • $n += 2;
  • $no织梦模板免费c += 2;
  • } elseif (224 <= $t && $t < 239) {
  • $tn = 3;
  • $n += 3;
  • $noc += 2;
  • } elseif (240 <= $t && $t <= 247) {
  • $tn = 4;
  • $n += 4;
  • $noc += 2;
  • } elseif (248 <= $t && $t <= 251) {
  • $tn = 5;
  • $n += 5;
  • $noc += 2;
  • } elseif ($t == 252 || $t == 253) {
  • $tn = 6;
  • $n += 6;
  • $noc += 2;
  • } else {
  • $n ++;
  • }
  • if ($noc >= $cutLen)break;
  • }
  • if ($noc > $cutLen) $n -= $tn;
  • $nStr = substr ( $str, 0, $n );
  • } else {
  • for($i = 0; $i < $cutLen – 1; $i ++) {
  • if (ord ( $str [$i] ) > 127) {

    关键词标签: 精准 函数 织梦

  • 声明: 本文由我的SEOUC技术文章主页发布于:2023-07-21 ,文章dedecms重新定义cn_substr函数截取字数更精准,织梦文主要讲述精准,函数,织梦网站建设源码以及服务器配置搭建相关技术文章。转载请保留链接: https://www.seouc.com/article/web_33481.html

    我的IDC 网站建设技术SEOUC.COM
    专注网站建设,SEO优化,小程序设计制作搭建开发定制网站等,数千家网站定制开发案例,网站推广技术服务。
  • 5000+合作客服
  • 8年从业经验
  • 150+覆盖行业
  • 最新热门源码技术文章