Laravel String Helper Functions

November 16, 2016 —John Koster

#String Helper Functions

String operations in PHP often seem complicated to developers coming to the language from other language, specifically languages that have a robust object-oriented approach to the provided data types. Operations such as checking if a particular string contains a substring, or if a string starts or ends with another string are not impossible, nor are they difficult, they just appear over-complicated or obscure. Luckily for us, Laravel has an amazing collection of string helper functions that we can use to perform some of the most common actions. The string helper functions are kept in the static class Illuminate\Support\Str. This post kicks off a series of articles covering the Laravel string helper functions.

#Immutable Strings

Laravel's string helper functions treat string values as immutable. This means that any given string passed as a function argument will be unchanged, and a new, modified copy of the string will be returned from the function (unless stated otherwise).

1use Illuminate\Support\Str;
2 
3$firstString = 'my words';
4 
5// Returns `MyWords`
6Str::studly($firstString);
7 
8// Displays 'my words'
9echo $firstString;

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.