Authored by 郝肖肖

店铺装修 经典推荐字符限制

... ... @@ -1069,4 +1069,25 @@ class Helpers
'item'
);
}
/**
* 截取字符串长度,超过用省略号表示
* @param type string $str 字符串
* @param type int $len 要截取的长度
* @return type string
*/
public static function substrEllipsis($str, $len)
{
return mb_substr($str, 0, $len, 'utf-8') . ($len >= mb_strlen($str,'utf-8') ? '' : '...');
}
/**
* 判断字符串是否包含中文
* @param type string $str 字符串
* @return type boolean
*/
public static function isChinese($str)
{
return preg_match("/[\x7f-\xff]/", $str);
}
}
... ...
... ... @@ -378,8 +378,10 @@ class ShopModel
foreach ($data['resource_data'] as $resource) {
$result[] = array(
'enName'=> $resource['enName'],
'name'=> $resource['name'],
'enName'=> Helpers::isChinese($resource['enName']) ?
Helpers::substrEllipsis($resource['enName'], 5) : Helpers::substrEllipsis($resource['enName'], 10),
'name'=> Helpers::isChinese($resource['name']) ?
Helpers::substrEllipsis($resource['name'], 5) : Helpers::substrEllipsis($resource['name'], 6),
'img'=> self::imageView2($resource['src'], 50, 50),
'title'=> $resource['title'],
'url'=> $resource['url'],
... ...