3v4l.org

run code in 300+ PHP versions simultaneously
<?php $text = "{tab=Text1} <p> nejaky</p><p>dlouhy text 1</p> ... {tab=Text2} <p>Jiny text...{test}.</p> {tab=Text3} .... {/tab} {tab=Text4} <p> nejaky</p><p>dlouhy text 1</p> ... "; $pattern="/(?:{tab=(?P<tab>[^}]+)})\n(?P<content>(?:(?!\n{\/?tab[^}]*}).)*)/s"; preg_match_all($pattern, $text, $matches); $result = []; if($matches) foreach($matches["tab"] as $i => $name) { if(isset($result[$name])) throw new Exception("Duplicate tab name '{$name}'"); $result[$name] = $matches["content"][$i]; } var_dump($result);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 28
Branch analysis from position: 9
2 jumps found. (Code = 77) Position 1 = 11, Position 2 = 27
Branch analysis from position: 11
2 jumps found. (Code = 78) Position 1 = 12, Position 2 = 27
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 22
Branch analysis from position: 15
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
Branch analysis from position: 27
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 27
Branch analysis from position: 28
filename:       /in/A6f5I
function name:  (null)
number of ops:  32
compiled vars:  !0 = $text, !1 = $pattern, !2 = $matches, !3 = $result, !4 = $name, !5 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '%7Btab%3DText1%7D%0A%3Cp%3E+nejaky%3C%2Fp%3E%3Cp%3Edlouhy+text+1%3C%2Fp%3E+...%0A+%0A%7Btab%3DText2%7D%0A%3Cp%3EJiny+text...%7Btest%7D.%3C%2Fp%3E%0A+%0A%7Btab%3DText3%7D%0A....%0A%7B%2Ftab%7D%0A%7Btab%3DText4%7D%0A%3Cp%3E+nejaky%3C%2Fp%3E%3Cp%3Edlouhy+text+1%3C%2Fp%3E+...%0A+%0A'
   17     1        ASSIGN                                                   !1, '%2F%28%3F%3A%7Btab%3D%28%3FP%3Ctab%3E%5B%5E%7D%5D%2B%29%7D%29%0A%28%3FP%3Ccontent%3E%28%3F%3A%28%3F%21%0A%7B%5C%2F%3Ftab%5B%5E%7D%5D%2A%7D%29.%29%2A%29%2Fs'
   18     2        INIT_FCALL                                               'preg_match_all'
          3        SEND_VAR                                                 !1
          4        SEND_VAR                                                 !0
          5        SEND_REF                                                 !2
          6        DO_ICALL                                                 
   20     7        ASSIGN                                                   !3, <array>
   22     8      > JMPZ                                                     !2, ->28
          9    >   FETCH_DIM_R                                      ~10     !2, 'tab'
         10      > FE_RESET_R                                       $11     ~10, ->27
         11    > > FE_FETCH_R                                       ~12     $11, !4, ->27
         12    >   ASSIGN                                                   !5, ~12
   23    13        ISSET_ISEMPTY_DIM_OBJ                         0          !3, !4
         14      > JMPZ                                                     ~14, ->22
         15    >   NEW                                              $15     'Exception'
         16        ROPE_INIT                                     3  ~17     'Duplicate+tab+name+%27'
         17        ROPE_ADD                                      1  ~17     ~17, !4
         18        ROPE_END                                      2  ~16     ~17, '%27'
         19        SEND_VAL_EX                                              ~16
         20        DO_FCALL                                      0          
         21      > THROW                                         0          $15
   24    22    >   FETCH_DIM_R                                      ~21     !2, 'content'
         23        FETCH_DIM_R                                      ~22     ~21, !5
         24        ASSIGN_DIM                                               !3, !4
         25        OP_DATA                                                  ~22
   22    26      > JMP                                                      ->11
         27    >   FE_FREE                                                  $11
   27    28    >   INIT_FCALL                                               'var_dump'
         29        SEND_VAR                                                 !3
         30        DO_ICALL                                                 
         31      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
155.83 ms | 1400 KiB | 17 Q