php convert title case to camel case 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 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');