- substr: documentation ( source)
- ucwords: documentation ( source)
- str_replace: documentation ( source)
- explode: documentation ( source)
- preg_replace: documentation ( source)
- strtolower: documentation ( source)
- ucfirst: documentation ( source)
<?php
function snakeToCamel($string)
{
$words = explode('_', $string);
$camel = '';
foreach ($words as $word) {
$camel .= ucfirst($word);
}
return $camel;
}
/**
* underdash_separated -> camelCase.
* @param string
* @return string
*/
function underdashToCamel($s)
{
$s = strtolower($s);
$s = preg_replace('#_(?=[a-z])#', ' ', $s);
$s = substr(ucwords('x' . $s), 1);
$s = str_replace(' ', '', $s);
return $s;
}
echo snakeToCamel("ahoj_vole_todle_1_je_PECKE__") . "\n";
echo underdashToCamel("ahoj_vole_todle_1_je_PECKE__") . "\n";