|
對(duì)于Thinkphp的截取字符串函數(shù)無(wú)法顯示省略號(hào)的情況,解決方法如下:
打開(kāi)Common/extend.php頁(yè)面,修改msubstr函數(shù)如下:
function msubstr($str, $start=0, $length, $charset="utf-8", $suffix=true){ if(function_exists("mb_substr")) { if($suffix) { if($str==mb_substr($str, $start, $length, $charset)) { return mb_substr($str, $start, $length, $charset); } else { return mb_substr($str, $start, $length, $charset)."..."; } } else { return mb_substr($str, $start, $length, $charset); } } elseif(function_exists('iconv_substr')) { if($suffix) { if($str==iconv_substr($str,$start,$length,$charset)) { return iconv_substr($str,$start,$length,$charset); } else { return iconv_substr($str,$start,$length,$charset)."..."; } } else { 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."…"; return $slice;}
php技術(shù):ThinkPHP的截取字符串函數(shù)無(wú)法顯示省略號(hào)的解決方法,轉(zhuǎn)載需保留來(lái)源!
鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。