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;
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 44) Position 1 = 12, Position 2 = 3
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 3
filename:       /in/SDYiO
function name:  (null)
number of ops:  14
compiled vars:  !0 = $str, !1 = $pattern, !2 = $replacement, !3 = $count
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, 'IF%281%3E10%2C+%22Large%22%2C+%22Medium%22%29%0AIF%281%3E10%2C+IF%2844%3E20%2C+%22Large%22%2C+%22Medium%22%29%2C+%22Small%22%29%0AIF%281%3E10%2C+IF%2844%3E20%2C+%22Large%22%2C+IF%284%3C5%2C+%22Tiny%22%2C+%22Medium%22%29%29%2C+%22Small%22%29%0AIF%28A1%3E10%2C+IF%28A1%3E20%2C+%22Large%22%2C+IF%28A1%3C5%2C+%22Tiny%22%2C+%22Medium%22%29%29%2C+%22Small%22%29'
    8     1        ASSIGN                                                   !1, '%7E%0A%23+subpatterns%0A%28%3F%3Cstring%3E+%22+%5B%5E%22%5C%5C%5D%2A%2B+%28%3Fs%3A+%5C%5C.+%5B%5E%22%5C%5C%5D%2A+%29%2A%2B+%22+%29%7B0%7D%0A%28%3F%3Cnparens%3E+%5C%28+%5B%5E%22%28%29%5D%2A%2B+%28%3F%3A+%5Cg%3Cstring%3E+%5B%5E%22%28%29%5D%2A+%7C+%5Cg%3Cnparens%3E+%5B%5E%22%28%29%5D%2A+%29%2A%2B+%5C%29+%29%7B0%7D%0A%28%3F%3Cother%3E+%5B%5E%22%28%29%5Cs%2C%5D+%28%3F%3A+%5B%5E%22%28%29%2C%5D%2A+%5B%5E%22%28%29%5Cs%2C%5D%29%3F+%29%7B0%7D%0A%28%3F%3Cpart%3E+%28%3F%3A+%5Cg%3Cstring%3E+%7C+%5Cg%3Cnparens%3E+%7C+%5Cg%3Cother%3E+%29%2A+%29%7B0%7D%0A%0A%23+main+pattern%0AIF%5C%28+%5Cs%2A+%28%5Cg%3Cpart%3E%29+%5Cs%2A+%2C+%5Cs%2A+%28%5Cg%3Cpart%3E%29+%5Cs%2A%2C+%5Cs%2A+%28%5Cg%3Cpart%3E%29+%5Cs%2A+%5C%29%0A%7Ex'
   22     2        ASSIGN                                                   !2, '%28%245%29+%3F+%28%246%29+%3A+%28%247%29'
   25     3    >   INIT_FCALL                                               'preg_replace'
          4        SEND_VAR                                                 !1
          5        SEND_VAR                                                 !2
          6        SEND_VAR                                                 !0
          7        SEND_VAL                                                 -1
          8        SEND_REF                                                 !3
          9        DO_ICALL                                         $7      
         10        ASSIGN                                                   !0, $7
   26    11      > JMPNZ                                                    !3, ->3
   28    12    >   ECHO                                                     !0
   29    13      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
149.63 ms | 1003 KiB | 15 Q