diff options
-rw-r--r-- | system/helpers/text_helper.php | 20 | ||||
-rw-r--r-- | user_guide/changelog.html | 1 |
2 files changed, 8 insertions, 13 deletions
diff --git a/system/helpers/text_helper.php b/system/helpers/text_helper.php index 30cec3148..21ab77830 100644 --- a/system/helpers/text_helper.php +++ b/system/helpers/text_helper.php @@ -40,27 +40,21 @@ */
if (! function_exists('word_limiter'))
{
- function word_limiter($str, $n = 100, $end_char = '…')
+ function word_limiter($str, $limit = 100, $end_char = '…')
{
- if (strlen($str) < $n)
+ if (trim($str) == '')
{
return $str;
}
- $words = explode(' ', preg_replace("/\s+/", ' ', preg_replace("/(\r\n|\r|\n)/", " ", $str)));
-
- if (count($words) <= $n)
- {
- return $str;
- }
+ preg_match('/^\s*+(?:\S++\s*+){1,'.(int) $limit.'}/', $str, $matches);
- $str = '';
- for ($i = 0; $i < $n; $i++)
+ if (strlen($str) == strlen($matches[0]))
{
- $str .= $words[$i].' ';
+ $end_char = '';
}
-
- return trim($str).$end_char;
+
+ return rtrim($matches[0]).$end_char;
}
}
diff --git a/user_guide/changelog.html b/user_guide/changelog.html index d20dd2efb..200b4c0e7 100644 --- a/user_guide/changelog.html +++ b/user_guide/changelog.html @@ -161,6 +161,7 @@ Change Log <h3>Bug fixes for Version 1.6.0</h3>
<ul>
+ <li>Fixed a bug (#1872) where word_limiter() was not retaining whitespace.</li>
<li>Fixed a bug (#1890) in csv_from_result() where content that included the delimiter would break the file.</li>
<li>Fixed a bug (#2542)in the clean_email() method of the Email class to allow for non-numeric / non-sequential array keys.</li>
<li>Fixed a bug (#2545) in <kbd>_html_entity_decode_callback()</kbd> when 'global_xss_filtering' is enabled.</li>
|