diff options
author | Thomas Lange <code@nerdmind.de> | 2017-11-28 23:46:09 +0100 |
---|---|---|
committer | Thomas Lange <code@nerdmind.de> | 2017-11-28 23:46:09 +0100 |
commit | 552fb9720ebba066b9b983a6415f7195e123216b (patch) | |
tree | 5aea47d694a365baabe084591d5a58dfc39ee4cc /core/functions.php | |
parent | 99a39cc80ea3eb6f58a87ab31452885f5cb60735 (diff) | |
download | blog-552fb9720ebba066b9b983a6415f7195e123216b.tar.gz blog-552fb9720ebba066b9b983a6415f7195e123216b.tar.xz blog-552fb9720ebba066b9b983a6415f7195e123216b.zip |
Bugfix: The "excerpt" function had returned a string with unnecessary whitespace between the truncated text and the $replace string ("[…]") if the truncated text from the regular expression had contained whitespace at the end (before it was concatenated with $replace). This issue has been fixed by passing the truncated text directly after truncation to the "trim" function (before the truncated text is concatenated with $replace). In addition, the now unnecessary "trim" call within the "excerpt" function has been removed.
Diffstat (limited to 'core/functions.php')
-rw-r--r-- | core/functions.php | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/core/functions.php b/core/functions.php index 6ef8894..1f7bfbb 100644 --- a/core/functions.php +++ b/core/functions.php @@ -232,7 +232,9 @@ function getRandomValue($length = 40): string { #=============================================================================== function cut($string, $length, $replace = ' […]') { if(mb_strlen($string) > $length) { - return preg_replace("/^(.{1,{$length}}\\b).*/su", "\\1{$replace}", $string); + return preg_replace_callback("/^(.{1,{$length}}\\b).*/su", function($match) { + return trim($match[1]); + }, $string).$replace; } return $string; @@ -245,7 +247,6 @@ function excerpt($string, $length = 500, $replace = ' […]') { $string = removeHTML($string); $string = removeDoubleLineBreaks($string); $string = cut($string, $length, $replace); - $string = trim($string); $string = nl2br($string); return $string; |