1 {$vons.title|msubstr=0,26} 像这样,总是显示错误,说msubstr函数未定义,
2 在使用这个函数之前是否需要引入什么文件?
3 Common/common.php中定义函数:
4
5 function msubstr($str, $start=0, $length, $charset="utf-8", $suffix=true)
6 {
7 if(function_exists("mb_substr")){
8 if ($suffix && strlen($str)>$length)
9 return mb_substr($str, $start, $length, $charset)."...";
10 else
11 return mb_substr($str, $start, $length, $charset);
12 }
13 elseif(function_exists('iconv_substr')) {
14 if ($suffix && strlen($str)>$length)
15 return iconv_substr($str,$start,$length,$charset)."...";
16 else
17 return iconv_substr($str,$start,$length,$charset);
18 }
19 $re['utf-8'] = "/[x01-x7f]|[xc2-xdf][x80-xbf]|[xe0-xef][x80-xbf]{2}|[xf0-xff][x80-xbf]{3}/";
20 $re['gb2312'] = "/[x01-x7f]|[xb0-xf7][xa0-xfe]/";
21 $re['gbk'] = "/[x01-x7f]|[x81-xfe][x40-xfe]/";
22 $re['big5'] = "/[x01-x7f]|[x81-xfe]([x40-x7e]|xa1-xfe])/";
23 preg_match_all($re[$charset], $str, $match);
24 $slice = join("",array_slice($match[0], $start, $length));
25 if($suffix) return $slice."…";
26 return $slice;
27 }
28
29 就是这么简单
echop sub_str
foreach($hot_goods_list AS $idx => $row){
$hot_goods_list[$idx]['goods_name'] = $GLOBALS['_CFG']['goods_name_length'] > 0 ?
sub_str($row['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $row['goods_name'];
}