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 $compute = create_function("", "return (" . $mathString . ");" ); return 0 + $compute(); } $string = " (1 + 1) * (2 + 2)"; echo calculate_string($string); // outputs 8
Output for git.master, git.master_jit, rfc.property-hooks
Warning: preg_replace(): Compilation failed: range out of order in character class at offset 9 in /in/34J44 on line 4 Fatal error: Uncaught Error: Call to undefined function create_function() in /in/34J44:5 Stack trace: #0 /in/34J44(10): calculate_string(NULL) #1 {main} thrown in /in/34J44 on line 5
Process exited with code 255.

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
52.91 ms | 401 KiB | 8 Q