3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php var_dump(stringToEnglishNumber('-214-277. 4404-', ', ')); function stringToEnglishNumber($string, $separator = ' ') { $sanitized = preg_replace("/[^\-0-9,. ]/", '', $string); $split = str_split($sanitized); if (empty($split)) { return $string; } if ($split[0] == '-') { $split[0] = 'negative'; } $convert = [ '-' => 'dash', '.' => 'dot', ' ' => 'space', ]; foreach ($split as $key => $char) { if (array_key_exists($char, $convert)) { $split[$key] = $convert[$char]; } } return implode("{$separator}", $split); }
based on 8WUPY
Output for 5.4.2 - 7.2.0
string(62) "negative, 2, 1, 4, dash, 2, 7, 7, dot, space, 4, 4, 0, 4, dash"
Output for 5.3.17 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/fTnKJ on line 20
Process exited with code 255.