truncateSafe() public static method

Truncate a string to a specified length without cutting a word off.
public static truncateSafe ( string $string, integer $length, string $append = '...' ) : string
$string string The string to truncate
$length integer The length to truncate the string to
$append string Text to append to the string IF it gets truncated, defaults to '...'
return string
Beispiel #1
0
 public function testTruncateSafe()
 {
     is('The quick brown fox...', Str::truncateSafe('The quick brown fox jumps over the lazy dog', 24));
     is('The quick brown fox jumps over the lazy dog', Str::truncateSafe('The quick brown fox jumps over the lazy dog', 55));
     is('Th...', Str::truncateSafe('The quick brown fox jumps over the lazy dog', 2));
     is('The...', Str::truncateSafe('The quick brown fox jumps over the lazy dog', 3));
     is('The...', Str::truncateSafe('The quick brown fox jumps over the lazy dog', 7));
 }