limitChars() public static method

Truncate the string to given length of characters.
public static limitChars ( string $string, integer $limit = 100, string $append = '...' ) : string
$string string The variable to truncate
$limit integer The length to truncate the string to
$append string Text to append to the string IF it gets truncated, defaults to '...'
return string
示例#1
0
 public function testLimitChars()
 {
     is('The quick brown fox jump...', Str::limitChars('The quick brown fox jumps over the lazy dog', 24));
     is('The quick brown fox jumps over the lazy dog', Str::limitChars('The quick brown fox jumps over the lazy dog', 55));
     is('Th...', Str::limitChars('The quick brown fox jumps over the lazy dog', 2));
     is('The...', Str::limitChars('The quick brown fox jumps over the lazy dog', 3));
     is('The qui...', Str::limitChars('The quick brown fox jumps over the lazy dog', 7));
     is('The quick brown fox jumps over the lazy dog', Str::limitChars('The quick brown fox jumps over the lazy dog', 150));
 }