mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-04-08 17:15:08 +02:00
lib: Add String::ellipsis()
This commit is contained in:
parent
f56ffd3426
commit
a0a3241d1c
@ -36,4 +36,22 @@ class String
|
||||
{
|
||||
return str_replace(' ', '', ucwords(str_replace($separator, ' ', strtolower($name))));
|
||||
}
|
||||
|
||||
/**
|
||||
* Add ellipsis when a string is longer than max length
|
||||
*
|
||||
* @param string $string
|
||||
* @param int $maxLength
|
||||
* @param string $ellipsis
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function ellipsis($string, $maxLength, $ellipsis = '...')
|
||||
{
|
||||
if (strlen($string) > $maxLength) {
|
||||
return substr($string, 0, $maxLength - strlen($ellipsis)) . $ellipsis;
|
||||
}
|
||||
|
||||
return $string;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user