aboutsummaryrefslogtreecommitdiffstats
path: root/core/functions.php
diff options
context:
space:
mode:
authorThomas Lange <code@nerdmind.de>2017-04-24 01:37:55 +0200
committerThomas Lange <code@nerdmind.de>2017-04-24 01:37:55 +0200
commit076c34c4f25c5695059d37e1bb6a262f6b7eedb6 (patch)
tree337c021850e6a6065d338305e127950560f74d23 /core/functions.php
parent1ab7ed73b0ea9d1f8597cf9b87bf272a7e6b99e6 (diff)
downloadblog-076c34c4f25c5695059d37e1bb6a262f6b7eedb6.tar.gz
blog-076c34c4f25c5695059d37e1bb6a262f6b7eedb6.tar.xz
blog-076c34c4f25c5695059d37e1bb6a262f6b7eedb6.zip
Nested function calls for generating the meta description are removed and a function was added to perform this task.
Diffstat (limited to 'core/functions.php')
-rw-r--r--core/functions.php17
1 files changed, 14 insertions, 3 deletions
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));
}
#===============================================================================
@@ -309,6 +309,17 @@ function excerpt($string, $length = 500, $replace = ' […]') {
}
#===============================================================================
+# 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
#===============================================================================
function makeSlugURL($string) {