Laravel 5.5 String Helper Function: camel_case

November 27, 2017 —John Koster

Camel casing is similar to studly case such that each word starts with a capitalized letter, with the difference being the first character is lower cased. Like the studly method, the camel method will not affect the casing of the rest of the word.

#Signature

The signature of the camel method is:

1public static function camel(
2 $value
3 );

#Example Use

The following examples will all return the string myWords:

1use Illuminate\Support\Str;
2 
3// myWords
4echo Str::camel('my words');
5 
6// myWords
7echo Str::camel('my-words');
8 
9// myWords
10echo Str::camel('my_words');
11 
12// myWords
13echo Str::camel(' my-words_');

Again, the camel function does not affect the casing of any characters after the first one.

1use Illuminate\Support\Str;
2 
3// mYWORDS
4echo Str::camel('MY WORDS');
5 
6// mywords
7echo Str::camel('mywords');

#camel_case($value)

The camel_case function is a shortcut to calling Str::camel. 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.