- var_dump: documentation ( source)
- strtoupper: documentation ( source)
- preg_replace: documentation ( source)
- preg_replace_callback_array: documentation ( source)
<?php
function camelize($id)
{
return preg_replace(array('/(^|_|-)+(.)/e', '/\.(.)/e'), array("strtoupper('\\2')", "'_'.strtoupper('\\1')"), $id);
}
function camelize2($id)
{
return preg_replace_callback_array([
'/(^|_|-)+(.)/e' => function ($match) {
return strtoupper($match[2]);
},
'/\.(.)/e' => function ($match) {
return '_' . strtoupper($match[1]);
}
], $id);
}
$text = "_salut_les-amis!!";
var_dump(camelize($text), camelize2($text));