From 076c34c4f25c5695059d37e1bb6a262f6b7eedb6 Mon Sep 17 00:00:00 2001 From: Thomas Lange Date: Mon, 24 Apr 2017 01:37:55 +0200 Subject: Nested function calls for generating the meta description are removed and a function was added to perform this task. --- core/functions.php | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'core/functions.php') diff --git a/core/functions.php b/core/functions.php index 471c14f..c6bdb1e 100644 --- a/core/functions.php +++ b/core/functions.php @@ -272,10 +272,10 @@ function removeDoubleLineBreaks($string): string { } #=============================================================================== -# Remove line breaks and tabs from a string +# Remove all multiple whitespace characters #=============================================================================== -function removeLineBreaksAndTabs($string, $replace = ''): string { - return str_replace(["\r\n", "\r", "\n", "\t"], $replace, $string); +function removeWhitespace($string): string { + return preg_replace('/\s+/S', ' ', trim($string)); } #=============================================================================== @@ -308,6 +308,17 @@ function excerpt($string, $length = 500, $replace = ' […]') { return $string; } +#=============================================================================== +# Return content for meta description +#=============================================================================== +function description($string, $length = 200, $replace = ' […]') { + $string = removeHTML($string); + $string = removeWhitespace($string); + $string = cut($string, $length, $replace); + + return $string; +} + #=============================================================================== # Generate a valid slug URL part from a string #=============================================================================== -- cgit v1.2.3