3v4l.org

run code in 300+ PHP versions simultaneously
<?php $a = 1; $b = 2; $content = <<<BLOCK <h1>Some Html</h1> <hr> {IF:($a + $b === 3)} <b>Yes :)</b> {ELSE} <b>No :(</b> {ENDIF} Another one... {IF:($a + $b === 4)} <b>:)</b> {ELSE} <b>:(</b> {ENDIF} Some more Text BLOCK; echo render($content); function render($content) { $match = preg_match_all('/{IF:\((.*?)\)}(.*?){ELSE}(.*?)({ENDIF})/s', $content, $matches, PREG_OFFSET_CAPTURE); if (!$match) { return $content; } $beforeIf = substr($content, 0, $matches[0][0][1]); $afterIf = substr($content, $matches[4][0][1] + strlen('{ENDIF}')); $evalCondition = eval('return (' . $matches[1][0][0] . ');'); if ($evalCondition) { $ifResult = $matches[2][0][0]; } else { $ifResult = $matches[3][0][0]; } return $beforeIf . $ifResult . render($afterIf); }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/jW9ND
function name:  (null)
number of ops:  17
compiled vars:  !0 = $a, !1 = $b, !2 = $content
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, 1
    4     1        ASSIGN                                                   !1, 2
    7     2        ROPE_INIT                                     9  ~6      '++++%3Ch1%3ESome+Html%3C%2Fh1%3E%0A++++%3Chr%3E%0A++++%7BIF%3A%28'
    9     3        ROPE_ADD                                      1  ~6      ~6, !0
          4        ROPE_ADD                                      2  ~6      ~6, '+%2B+'
          5        ROPE_ADD                                      3  ~6      ~6, !1
          6        ROPE_ADD                                      4  ~6      ~6, '+%3D%3D%3D+3%29%7D%0A++++++++%3Cb%3EYes+%3A%29%3C%2Fb%3E%0A++++%7BELSE%7D%0A++++++++%3Cb%3ENo+%3A%28%3C%2Fb%3E%0A%09%7BENDIF%7D%0A%09%0A%09Another+one...%0A%09%7BIF%3A%28'
   16     7        ROPE_ADD                                      5  ~6      ~6, !0
          8        ROPE_ADD                                      6  ~6      ~6, '+%2B+'
          9        ROPE_ADD                                      7  ~6      ~6, !1
         10        ROPE_END                                      8  ~5      ~6, '+%3D%3D%3D+4%29%7D%0A++++++++%3Cb%3E%3A%29%3C%2Fb%3E%0A++++%7BELSE%7D%0A++++++++%3Cb%3E%3A%28%3C%2Fb%3E%0A%09%7BENDIF%7D%0A%09%0A%09Some+more+Text'
    6    11        ASSIGN                                                   !2, ~5
   25    12        INIT_FCALL_BY_NAME                                       'render'
         13        SEND_VAR_EX                                              !2
         14        DO_FCALL                                      0  $12     
         15        ECHO                                                     $12
   48    16      > RETURN                                                   1

Function render:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 11
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 37, Position 2 = 42
Branch analysis from position: 37
1 jumps found. (Code = 42) Position 1 = 46
Branch analysis from position: 46
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 42
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/jW9ND
function name:  render
number of ops:  53
compiled vars:  !0 = $content, !1 = $match, !2 = $matches, !3 = $beforeIf, !4 = $afterIf, !5 = $evalCondition, !6 = $ifResult
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   RECV                                             !0      
   28     1        INIT_FCALL                                               'preg_match_all'
          2        SEND_VAL                                                 '%2F%7BIF%3A%5C%28%28.%2A%3F%29%5C%29%7D%28.%2A%3F%29%7BELSE%7D%28.%2A%3F%29%28%7BENDIF%7D%29%2Fs'
          3        SEND_VAR                                                 !0
          4        SEND_REF                                                 !2
          5        SEND_VAL                                                 256
          6        DO_ICALL                                         $7      
          7        ASSIGN                                                   !1, $7
   30     8        BOOL_NOT                                         ~9      !1
          9      > JMPZ                                                     ~9, ->11
   31    10    > > RETURN                                                   !0
   34    11    >   INIT_FCALL                                               'substr'
         12        SEND_VAR                                                 !0
         13        SEND_VAL                                                 0
         14        FETCH_DIM_R                                      ~10     !2, 0
         15        FETCH_DIM_R                                      ~11     ~10, 0
         16        FETCH_DIM_R                                      ~12     ~11, 1
         17        SEND_VAL                                                 ~12
         18        DO_ICALL                                         $13     
         19        ASSIGN                                                   !3, $13
   35    20        INIT_FCALL                                               'substr'
         21        SEND_VAR                                                 !0
         22        FETCH_DIM_R                                      ~15     !2, 4
         23        FETCH_DIM_R                                      ~16     ~15, 0
         24        FETCH_DIM_R                                      ~17     ~16, 1
         25        ADD                                              ~18     ~17, 7
         26        SEND_VAL                                                 ~18
         27        DO_ICALL                                         $19     
         28        ASSIGN                                                   !4, $19
   36    29        FETCH_DIM_R                                      ~21     !2, 1
         30        FETCH_DIM_R                                      ~22     ~21, 0
         31        FETCH_DIM_R                                      ~23     ~22, 0
         32        CONCAT                                           ~24     'return+%28', ~23
         33        CONCAT                                           ~25     ~24, '%29%3B'
         34        INCLUDE_OR_EVAL                                  $26     ~25, EVAL
         35        ASSIGN                                                   !5, $26
   38    36      > JMPZ                                                     !5, ->42
   39    37    >   FETCH_DIM_R                                      ~28     !2, 2
         38        FETCH_DIM_R                                      ~29     ~28, 0
         39        FETCH_DIM_R                                      ~30     ~29, 0
         40        ASSIGN                                                   !6, ~30
   38    41      > JMP                                                      ->46
   41    42    >   FETCH_DIM_R                                      ~32     !2, 3
         43        FETCH_DIM_R                                      ~33     ~32, 0
         44        FETCH_DIM_R                                      ~34     ~33, 0
         45        ASSIGN                                                   !6, ~34
   46    46    >   CONCAT                                           ~36     !3, !6
   47    47        INIT_FCALL_BY_NAME                                       'render'
         48        SEND_VAR_EX                                              !4
         49        DO_FCALL                                      0  $37     
         50        CONCAT                                           ~38     ~36, $37
         51      > RETURN                                                   ~38
   48    52*     > RETURN                                                   null

End of function render

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
147.94 ms | 1008 KiB | 15 Q