snake->Camel
<?php
function camelize($str) {
$str = ucwords($str, '_');
return str_replace('_', '', $str);
}
// test
echo camelize('foo_goo_hoo'); //FooGooHoo
Camel->snake
<?php
function snakize($str) {
$str = preg_replace('/[a-z]+(?=[A-Z])|[A-Z]+(?=[A-Z][a-z])/', '\0_', $str);
return strtolower($str);
}
// test
echo snakize('getURLAndInfo'); //get_url_and_info
この辺参考になります。(LICENSEはdietcake参照)
https://github.com/dietcake/dietcake/blob/master/core/inflector.php#L28