php convert string to camelcase code example
Example 1: php ucfirst all words
$foo = 'hello world!';
$foo = ucwords($foo);
$bar = 'HELLO WORLD!';
$bar = ucwords($bar);
$bar = ucwords(strtolower($bar));
$foo = 'hello|world!';
$bar = ucwords($foo);
$baz = ucwords($foo, "|");
Example 2: php uppercase each word
$upperCaseSentance=ucwords("i do not feel good");
Example 3: php function to convert string to camelcase
echo ucwords("hello world");
Example 4: php string underscore into camelcase
function dashesToCamelCase($string, $capitalizeFirstCharacter = false)
{
$str = str_replace(' ', '', ucwords(str_replace('-', ' ', $string)));
if (!$capitalizeFirstCharacter) {
$str[0] = strtolower($str[0]);
}
return $str;
}
echo dashesToCamelCase('this-is-a-string');