Commit 0ba6b572 authored by Nigel McNie's avatar Nigel McNie
Browse files

Added a function to shorten a string putting '...' in the middle.

parent 52e65ecf
......@@ -1631,4 +1631,20 @@ function display_size($size) {
}
return $size;
}
/**
* Takes a string and a length, and ensures that the string is no longer than
* this length, by putting '...' in the middle
*
* @param string $str String to shorten
* @param int $maxlen The maximum length the new string should be
* @return string
*/
function str_shorten($str, $maxlen) {
if (strlen($str) > ($maxlen - 3)) {
return substr($str, 0, floor($maxlen / 2) - 1) . '...' . substr($str, -(floor($maxlen / 2) - 2));
}
return $str;
}
?>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment