From 91cad0f435e337102a8a048669f5c79699f4d681 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E7=A7=A6?= Date: Tue, 14 Apr 2015 21:31:43 +0800 Subject: [PATCH] fix Helper\summary bug MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修正当 `$value` 中没有空格时(中文订阅的内容), 在进行截取时会出现返回 ` [...]` 的情况. --- lib/helpers.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/helpers.php b/lib/helpers.php index f483fcb..5365a7d 100644 --- a/lib/helpers.php +++ b/lib/helpers.php @@ -116,7 +116,11 @@ function summary($value, $min_length = 5, $max_length = 120, $end = '[...]') $length = strlen($value); 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) { return '';