Transform a string between
camelCase
,PascalCase
,Headline Case
,snake_case
,param-case
,CONSTANT_CASE
and others.
You can install the package via composer:
composer require realodix/change-case
use Realodix\ChangeCase\ChangeCase;
camelCase
CONSTANT_CASE
dot.case
Header-Case
Headline Case
kebab-case
no case
PascalCase
path/case
Sentence case
snake_case
swapCase
Every method that gets 💡 flag, they can support option
delimiter
: (string) This character separates each chunk of data within the text string. Default: singgle space.splitRx
: (RegExp) Used to split into word segments.stripRx
: (RegExp) Used to remove extraneous characters.separateNum
: (bool) Used to separate numbers or not. Default: false.apostrophe
: (bool) Used to separate apostrophe or not. Default: false.
Examples
ChangeCase::header('TestV2', ['separateNum' => true]);
// 'Test-V-2'
Transform into a string with the separator denoted by the next word capitalized.
💡 Support options
ChangeCase::camel('test string');
// 'testString'
ChangeCase::camel('1twoThree');
// '1twoThree'
ChangeCase::camel('1twoThree', ['separateNum' => true]);
// '1TwoThree'
Transform into upper case string with an underscore between words.
ChangeCase::constant('test string');
// 'TEST_STRING'
Transform into a lower case string with a period between words.
💡 Support options
ChangeCase::dot('test string');
// 'test.string'
Transform into a dash separated string of capitalized words.
💡 Support options
ChangeCase::header('test string');
// 'Test-String'
Transform a strings delimited by casing, hyphens, or underscores into a space delimited string with each word's first letter capitalized.
ChangeCase::headline('test string');
// 'Test String'
ChangeCase::headline('steve_jobs');
// Steve Jobs
ChangeCase::headline('EmailNotificationSent');
// Email Notification Sent
Transform into a lower cased string with dashes between words.
💡 Support options
ChangeCase::kebab('test string');
// 'test-string'
ChangeCase::kebab('Foo123Bar');
// 'foo123-bar'
ChangeCase::kebab('Foo123Bar', ['separateNum' => true]);
// 'foo-123-bar'
Transform into a lower cased string with spaces between words, and clean up the string from non-word characters.
💡 Support options
ChangeCase::no('testString');
// 'test string'
ChangeCase::no('Foo123Bar')
// foo123 bar
ChangeCase::no('Foo123Bar', ['separateNum' => true])
// foo 123 bar
Transform into a string of capitalized words without separators.
💡 Support options
ChangeCase::pascal('test string');
// 'TestString'
Transform into a lower case string with slashes between words.
💡 Support options
ChangeCase::path('test string');
// 'test/string'
Transform into a lower case with spaces between words, then capitalize the string.
💡 Support options
ChangeCase::sentence('testString');
// 'Test string'
Transform into a lower case string with underscores between words.
💡 Support options
ChangeCase::snake('test string');
// 'test_string'
ChangeCase::snake('Foo123Bar');
// 'foo123_bar'
ChangeCase::snake('Foo123Bar', ['separateNum' => true]);
// 'foo_123_bar'
Transform a string by swapping every character from upper to lower case, or lower to upper case.
ChangeCase::swap('Test String');
// 'tEST sTRING'
The MIT License (MIT). Please see License File for more information.