3v4l.org

run code in 300+ PHP versions simultaneously
<?php $str = 'IF(1>10, "Large", "Medium") IF(1>10, IF(44>20, "Large", "Medium"), "Small") IF(1>10, IF(44>20, "Large", IF(4<5, "Tiny", "Medium")), "Small") IF(A1>10, IF(A1>20, "Large", IF(A1<5, "Tiny", "Medium")), "Small")'; $pattern =<<<'REGEX' ~ # subpatterns (?<string> " [^"\\]*+ (?s: \\. [^"\\]* )*+ " ){0} (?<nparens> \( [^"()]*+ (?: \g<string> [^"()]* | \g<nparens> [^"()]* )*+ \) ){0} (?<other> [^"()\s,] (?: [^"(),]* [^"()\s,])? ){0} (?<part> (?: \g<string> | \g<nparens> | \g<other> )* ){0} # main pattern IF\( \s* (\g<part>) \s* , \s* (\g<part>) \s*, \s* (\g<part>) \s* \) ~x REGEX; //$replacement = '($7) ? ($8) : ($9)'; $replacement = '($5) ? ($6) : ($7)'; do { $str = preg_replace($pattern, $replacement, $str, -1, $count); } while ($count); echo $str;
Output for git.master_jit, git.master
(1>10) ? ("Large") : ("Medium") (1>10) ? ((44>20) ? ("Large") : ("Medium")) : ("Small") (1>10) ? ((44>20) ? ("Large") : ((4<5) ? ("Tiny") : ("Medium"))) : ("Small") (A1>10) ? ((A1>20) ? ("Large") : ((A1<5) ? ("Tiny") : ("Medium"))) : ("Small")

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:
38.7 ms | 405 KiB | 5 Q