diff options
author | Robin Appelman <icewind@owncloud.com> | 2012-11-21 22:37:14 +0100 |
---|---|---|
committer | Robin Appelman <icewind@owncloud.com> | 2012-11-21 22:37:14 +0100 |
commit | 97380f3485fe40120b361f2f0bc9d12d060d6311 (patch) | |
tree | 1e03f5375f2d9f97770fee8b6aafaf627c998b01 /lib/helper.php | |
parent | 40fae0acbf2e84782c273a82eb10a2ed9fdf8162 (diff) | |
parent | 495a8da354eb5aee4bda65138b51da7fab74cef2 (diff) | |
download | nextcloud-server-97380f3485fe40120b361f2f0bc9d12d060d6311.tar.gz nextcloud-server-97380f3485fe40120b361f2f0bc9d12d060d6311.zip |
merge master into filesystem
Diffstat (limited to 'lib/helper.php')
-rw-r--r-- | lib/helper.php | 16 |
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; + } + } |