- var_dump: documentation ( source)
- preg_replace_callback: documentation ( source)
- str_replace: documentation ( source)
- strtolower: documentation ( source)
<?php
function fromCamelCaseToUnderscores($str)
{
$str[0] = strtolower($str[0]); // Just in case first character is uppercase.
$str = str_replace('ID', 'Id', $str); // Hack for the way CATS defies camelCase convention
return preg_replace_callback('/([A-Z])/', function($char)
{
return '_' . strtolower($char[1]);
}, $str);
}
var_dump(fromCamelCaseToUnderscores(null));