3v4l.org

run code in 300+ PHP versions simultaneously
<?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));

preferences:
70.66 ms | 402 KiB | 5 Q