- preg_replace: documentation ( source)
<?php
function snakeToCamel($text, $firstUpper = true)
{
$regex = '/(';
if ($firstUpper) {
$regex .= '^|';
}
$regex .= '_)([a-z])/e';
return preg_replace($regex, "strtoupper('\\2')", $text);
}
echo snakeToCamel('testFooBar');