From 589dbae47455cd34543c9eeab32bdbdc8762fa7c Mon Sep 17 00:00:00 2001 From: Sven Slootweg Date: Fri, 29 Jun 2012 11:39:11 +0200 Subject: [PATCH] Replace cut_text with own regex-based version --- include.misc.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/include.misc.php b/include.misc.php index c246cb7..f4d496b 100644 --- a/include.misc.php +++ b/include.misc.php @@ -174,6 +174,25 @@ function strip_tags_attr($string, $allowtags = NULL, $allowattributes = NULL) return $string; } +function cut_text($input, $length) +{ + if(strlen($input) > $length) + { + if(preg_match("/^(.{0,{$length}})\W/s", $input, $matches)) + { + return $matches[1] . "..."; + } + else + { + return ""; + } + } + else + { + return $input; + } +} + function cut_text($value, $length) { /* Thanks to highstrike at gmail dot com (http://www.php.net/manual/en/function.substr.php#80247) */