Laravel String Helper Function: length

November 16, 2016 —John Koster

The length helper method simply returns the length of the given $value, using PHP's internal character encoding.

The signature for the length helper method is:

length($value)

1use Illuminate\Support\Str;
2 
3// 5
4echo Str::length('12345');
5 
6// 120
7echo Str::length(str_repeat('n', 120));
str_repeat($input, $multiplier)

str_repeat is a function built into PHP that repeats a given $input $multiplier number of times. So calling str_repeat('n', 120) results in a string containing 120 occurrences of the character n.

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.