3v4l.org

run code in 300+ PHP versions simultaneously
<?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
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
string(19) "414158-387896-26262" Fatal error: Uncaught Error: Call to undefined function create_function() in /in/PNo2h:6 Stack trace: #0 /in/PNo2h(11): calculate_string('414158-387896-2...') #1 {main} thrown in /in/PNo2h on line 6
Process exited with code 255.
Output for 7.2.0 - 7.2.33, 7.3.0 - 7.3.31, 7.4.0 - 7.4.33
string(19) "414158-387896-26262" Deprecated: Function create_function() is deprecated in /in/PNo2h on line 6 0
Output for 5.4.2 - 5.4.45, 5.5.24 - 5.5.35, 5.6.7 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.33, 7.3.32 - 7.3.33
string(19) "414158-387896-26262" 0

preferences:
204.77 ms | 403 KiB | 272 Q