3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function calculate_string( $mathString ) { $mathString = trim($mathString); // trim white spaces $mathString = preg_replace('#[^0-9\+\-\*\/\(\) ]#', '', $mathString); // remove any non-numbers chars; exception for math operators var_dump($mathString); $compute = create_function("", "return (" . $mathString . ");" ); return 0 + $compute(); } $string = " 4141.58-3878.96-262.62"; echo calculate_string($string); // outputs 8
based on MX8XM
Output for 7.2.0
string(19) "414158-387896-26262" Deprecated: Function create_function() is deprecated in /in/PNo2h on line 6 0
Output for 5.3.18 - 7.1.10
string(19) "414158-387896-26262" 0