summaryrefslogtreecommitdiffstats
path: root/lib/helper.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/helper.php')
-rw-r--r--lib/helper.php16
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/helper.php b/lib/helper.php
index 2b63778024d..536b70b074a 100644
--- a/lib/helper.php
+++ b/lib/helper.php
@@ -743,4 +743,20 @@ class OC_Helper {
return false;
}
+
+ /**
+ * Shortens str to maxlen by replacing characters in the middle with '...', eg.
+ * ellipsis('a very long string with lots of useless info to make a better example', 14) becomes 'a very ...example'
+ * @param string $str the string
+ * @param string $maxlen the maximum length of the result
+ * @return string with at most maxlen characters
+ */
+ public static function ellipsis($str, $maxlen) {
+ if (strlen($str) > $maxlen) {
+ $characters = floor($maxlen / 2);
+ return substr($str, 0, $characters) . '...' . substr($str, -1 * $characters);
+ }
+ return $str;
+ }
+
}