午夜国产狂喷潮在线观看|国产AⅤ精品一区二区久久|中文字幕AV中文字幕|国产看片高清在线

    dedecms重新定義cn_substr函數(shù)截取字?jǐn)?shù)更準(zhǔn)確
    來源:易賢網(wǎng) 閱讀:1016 次 日期:2014-09-24 14:48:26
    溫馨提示:易賢網(wǎng)小編為您整理了“dedecms重新定義cn_substr函數(shù)截取字?jǐn)?shù)更準(zhǔn)確”,方便廣大網(wǎng)友查閱!

    方法說明:

    一、找到\include\helpers\string.helper.php把原來約33到102行(也就是定義cn_substr()函數(shù)的那段代碼)替換掉,你要是怕不行,可以先把這個(gè)文件備份下,親;

    代碼如下:

    /**

    * 中英文截取字符串,漢字安2個(gè)字節(jié)

    *

    * @access public

    * @param string $str 需要截取的字符串

    * @param int $cutLen 截取的長度

    * @param bool $cutSlashes 是否去掉\

    * @param bool $addSlashes 是加\

    * @param string $oDot 截取后加的字符串,如經(jīng)常用的三個(gè)點(diǎn)

    * @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 ( “/(\<[^\<]*\>|\r|\n|\s|\[.+?\])/is”, ‘ ‘, $str );

    $str = htmlspecialchars ( $str );

    }else{

    $str = htmlspecialchars ( $str );

    }

    if ($cutLen && strlen ( $str ) > $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 <= $t && $t <= 126)) {

    $tn = 1;

    $n ++;

    $noc ++;

    } elseif (194 <= $t && $t <= 223) {

    $tn = 2;

    $n += 2;

    $noc += 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) {

    $nStr .= $str [$i] . $str [$i + 1];

    $i ++;

    } else {

    $nStr .= $str [$i];

    }

    }

    }

    $str = $nStr . $oDot;

    }

    if ($addSlashes) $str = addslashes ( $str );

    $str = htmlspecialchars_decode ( $str );

    return trim ( $str );

    }

    }

    二、全站都使用cn_substr()函數(shù),不管你程序是gbk還是utf8;

    比如你要調(diào)用10個(gè)字(拼音漢字混雜):[field:title function='cn_substr(@me,20)']即可

    更多信息請(qǐng)查看IT技術(shù)專欄

    更多信息請(qǐng)查看CMS教程
    由于各方面情況的不斷調(diào)整與變化,易賢網(wǎng)提供的所有考試信息和咨詢回復(fù)僅供參考,敬請(qǐng)考生以權(quán)威部門公布的正式信息和咨詢?yōu)闇?zhǔn)!
    相關(guān)閱讀CMS教程

    2025國考·省考課程試聽報(bào)名

    • 報(bào)班類型
    • 姓名
    • 手機(jī)號(hào)
    • 驗(yàn)證碼
    關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡(jiǎn)要咨詢 | 簡(jiǎn)要咨詢須知 | 新媒體/短視頻平臺(tái) | 手機(jī)站點(diǎn) | 投訴建議
    工業(yè)和信息化部備案號(hào):滇ICP備2023014141號(hào)-1 云南省教育廳備案號(hào):云教ICP備0901021 滇公網(wǎng)安備53010202001879號(hào) 人力資源服務(wù)許可證:(云)人服證字(2023)第0102001523號(hào)
    云南網(wǎng)警備案專用圖標(biāo)
    聯(lián)系電話:0871-65099533/13759567129 獲取招聘考試信息及咨詢關(guān)注公眾號(hào):hfpxwx
    咨詢QQ:1093837350(9:00—18:00)版權(quán)所有:易賢網(wǎng)
    云南網(wǎng)警報(bào)警專用圖標(biāo)