fix Helper\summary bug

修正当 `$value` 中没有空格时(中文订阅的内容), 在进行截取时会出现返回 ` [...]` 的情况.
This commit is contained in:
小秦 2015-04-14 21:31:43 +08:00
parent 46d69b15f6
commit 91cad0f435

View File

@ -116,7 +116,11 @@ function summary($value, $min_length = 5, $max_length = 120, $end = '[...]')
$length = strlen($value); $length = strlen($value);
if ($length > $max_length) { if ($length > $max_length) {
return substr($value, 0, strpos($value, ' ', $max_length)).' '.$end; $max = strpos($value, ' ', $max_length);
if ($max === false) {
$max = $max_length;
}
return substr($value, 0, $max).' '.$end;
} }
else if ($length < $min_length) { else if ($length < $min_length) {
return ''; return '';