3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function do_split($name) { return preg_split('/([A-Z]{2,}|([A-Z][^A-Z]*))/', $name, null, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); } function convert_case($name) { return implode( '_', array_map( 'strtolower', do_split($name) ) ); } function convert_case2($name) { $words = array(); $prev = ''; for ($i = 0; $i < strlen($name); $i++) { $char = $name[$i]; echo "{$char} " . (ctype_upper($char) ? 'true' : 'false') . "\n"; } return strtolower(implode('_', $output)); } convert_case2('FooBARbar0123'); $samples = array( 'FooBar', 'FooBAR', 'FOOBar', 'foo_bar', 'FOO_bar', 'foo_BAR', 'foo_Bar', 'Foo_bar', ); /* print_r(array_map(function ($name) { return array( 'name' => $name, 'split' => do_split($name), 'converted' => convert_case($name), ); }, $samples)); */
based on qUX0l
Output for 5.2.5 - 5.6.28, 7.0.0 - 7.1.0
F true o false o false B true A true R true b false a false r false 0 false 1 false 2 false 3 false Notice: Undefined variable: output in /in/8BNFN on line 24 Warning: implode(): Invalid arguments passed in /in/8BNFN on line 24
Output for hhvm-3.12.0
F true o false o false B true A true R true b false a false r false 0 false 1 false 2 false 3 false Notice: Undefined variable: output in /in/8BNFN on line 24 Warning: Invalid operand type was used: implode() expects a container as one of the arguments in /in/8BNFN on line 24
Output for hhvm-3.10.0

Process exited with code 153.
Output for 5.0.4 - 5.2.4
F true o false o false B true A true R true b false a false r false 0 false 1 false 2 false 3 false Notice: Undefined variable: output in /in/8BNFN on line 24 Warning: implode(): Bad arguments. in /in/8BNFN on line 24
Output for 4.3.2 - 5.0.3
F true o false o false B true A true R true b false a false r false 0 false 1 false 2 false 3 false Notice: Undefined variable: output in /in/8BNFN on line 24 Warning: implode(): Bad arguments. in /in/8BNFN on line 24
Output for 4.3.0 - 4.3.1
F true o false o false B true A true R true b false a false r false 0 false 1 false 2 false 3 false Notice: Undefined variable: output in /in/8BNFN on line 24 Warning: implode() [http://www.php.net/function.implode]: Bad arguments. in /in/8BNFN on line 24