Laravel String Helper Function: limit

November 16, 2016 —John Koster

The limit method will make sure that the $value is never longer than the given limit. If it is, the length is reduced and the specified end is added as a suffix. This method is useful when displaying output from a user that could be very long and potentially cause issues with user interface layouts. If the exact output length is important, it is possible that the final length is the sum of the $limit and the length of the $end sequence.

The signature for the limit helper method is:

limit($value, $limit = 100, $end = '...')

1use Illuminate\Support\Str;
2 
3// Hello...
4echo Str::limit('Hello world', 5);
5 
6// Hello wo...
7echo Str::limit('Hello wo...', 8);

#str_limit($value, $limit = 100, $end = '...')

The str_limit function is a shortcut to calling Str::limit. This function is declared in the global namespace.

Some absolutely amazing
people

The following amazing people help support this site and my open source projects ♥️
If you're interesting in supporting my work and want to show up on this list, check out my GitHub Sponsors Profile.