3v4l.org

run code in 300+ PHP versions simultaneously
<?php $articles = [ (object)['text' => 'Some text {reillorama:5/dots/1} some text {reillorama:12/foo}'], (object)['text' => 'Only text with no placeholders'], (object)['text' => 'Some text {reillorama:33} some text {reillorama:1/bar} some text'], (object)['text' => 'Some text {reillorama:5/word} some text {reillorama:2} some text {reillorama:555555/noSpacesInWord/7777777}'], (object)['text' => 'The pattern also allows the middle parameter to be omitted {reillorama:6/7}'], ]; $firstLookup = [5 => 'five', 12 => 'twelve', 1 => 'one', 2 => 'two']; $secondLookup = ['foo' => 'fighters', 'bar' => 'none', 'word' => 'up', 'noSpacesInWord' => 'replacement']; $thirdLookup = [1 => 'another one', 7 => 'seven']; foreach ($articles as $article) { $article->text = preg_replace_callback( '~{reillorama:(\d+)(?:/([a-z]+))?(?:/(\d+))?}~i', function($m) use ($firstLookup, $secondLookup, $thirdLookup) { return '**' . ($firstLookup[$m[1]] ?? '[first not found]') . ($m[2] === null ? '' : (isset($secondLookup[$m[2]]) ? $secondLookup[$m[2]] : '[second not found]')) . ($m[3] === null ? '' : (isset($thirdLookup[$m[3]]) ? $thirdLookup[$m[3]] : '[third not found]')) . '**'; //var_export($m); if you want to see what is in the matches array }, $article->text, -1, $count, PREG_UNMATCHED_AS_NULL ); echo "{$article->text}\n---\n"; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 15, Position 2 = 36
Branch analysis from position: 15
2 jumps found. (Code = 78) Position 1 = 16, Position 2 = 36
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
Branch analysis from position: 36
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 36
filename:       /in/7mDqd
function name:  (null)
number of ops:  38
compiled vars:  !0 = $articles, !1 = $firstLookup, !2 = $secondLookup, !3 = $thirdLookup, !4 = $article, !5 = $count
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   CAST                                          8  ~6      <array>
          1        INIT_ARRAY                                       ~7      ~6
    5     2        CAST                                          8  ~8      <array>
          3        ADD_ARRAY_ELEMENT                                ~7      ~8
    6     4        CAST                                          8  ~9      <array>
          5        ADD_ARRAY_ELEMENT                                ~7      ~9
    7     6        CAST                                          8  ~10     <array>
          7        ADD_ARRAY_ELEMENT                                ~7      ~10
    8     8        CAST                                          8  ~11     <array>
          9        ADD_ARRAY_ELEMENT                                ~7      ~11
    3    10        ASSIGN                                                   !0, ~7
   11    11        ASSIGN                                                   !1, <array>
   12    12        ASSIGN                                                   !2, <array>
   13    13        ASSIGN                                                   !3, <array>
   15    14      > FE_RESET_R                                       $16     !0, ->36
         15    > > FE_FETCH_R                                               $16, !4, ->36
   16    16    >   INIT_FCALL                                               'preg_replace_callback'
   17    17        SEND_VAL                                                 '%7E%7Breillorama%3A%28%5Cd%2B%29%28%3F%3A%2F%28%5Ba-z%5D%2B%29%29%3F%28%3F%3A%2F%28%5Cd%2B%29%29%3F%7D%7Ei'
   18    18        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2F7mDqd%3A18%240'
         19        BIND_LEXICAL                                             ~18, !1
         20        BIND_LEXICAL                                             ~18, !2
         21        BIND_LEXICAL                                             ~18, !3
   25    22        SEND_VAL                                                 ~18
   26    23        FETCH_OBJ_R                                      ~19     !4, 'text'
         24        SEND_VAL                                                 ~19
   27    25        SEND_VAL                                                 -1
   28    26        SEND_REF                                                 !5
   29    27        SEND_VAL                                                 512
         28        DO_ICALL                                         $20     
   16    29        ASSIGN_OBJ                                               !4, 'text'
   29    30        OP_DATA                                                  $20
   31    31        FETCH_OBJ_R                                      ~21     !4, 'text'
         32        NOP                                                      
         33        FAST_CONCAT                                      ~22     ~21, '%0A---%0A'
         34        ECHO                                                     ~22
   15    35      > JMP                                                      ->15
         36    >   FE_FREE                                                  $16
   32    37      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2F7mDqd%3A18%240:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 14
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 23
Branch analysis from position: 23
2 jumps found. (Code = 43) Position 1 = 27, Position 2 = 29
Branch analysis from position: 27
1 jumps found. (Code = 42) Position 1 = 38
Branch analysis from position: 38
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 29
2 jumps found. (Code = 43) Position 1 = 32, Position 2 = 36
Branch analysis from position: 32
1 jumps found. (Code = 42) Position 1 = 37
Branch analysis from position: 37
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 36
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 21
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 22
Branch analysis from position: 22
2 jumps found. (Code = 43) Position 1 = 27, Position 2 = 29
Branch analysis from position: 27
Branch analysis from position: 29
Branch analysis from position: 21
2 jumps found. (Code = 43) Position 1 = 27, Position 2 = 29
Branch analysis from position: 27
Branch analysis from position: 29
filename:       /in/7mDqd
function name:  {closure}
number of ops:  42
compiled vars:  !0 = $m, !1 = $firstLookup, !2 = $secondLookup, !3 = $thirdLookup
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
          2        BIND_STATIC                                              !2
          3        BIND_STATIC                                              !3
   20     4        FETCH_DIM_R                                      ~4      !0, 1
          5        FETCH_DIM_IS                                     ~5      !1, ~4
          6        COALESCE                                         ~6      ~5
          7        QM_ASSIGN                                        ~6      '%5Bfirst+not+found%5D'
          8        CONCAT                                           ~7      '%2A%2A', ~6
   21     9        FETCH_DIM_R                                      ~8      !0, 2
         10        TYPE_CHECK                                    2          ~8
         11      > JMPZ                                                     ~9, ->14
         12    >   QM_ASSIGN                                        ~10     ''
         13      > JMP                                                      ->23
         14    >   FETCH_DIM_R                                      ~11     !0, 2
         15        ISSET_ISEMPTY_DIM_OBJ                         0          !2, ~11
         16      > JMPZ                                                     ~12, ->21
         17    >   FETCH_DIM_R                                      ~13     !0, 2
         18        FETCH_DIM_R                                      ~14     !2, ~13
         19        QM_ASSIGN                                        ~15     ~14
         20      > JMP                                                      ->22
         21    >   QM_ASSIGN                                        ~15     '%5Bsecond+not+found%5D'
         22    >   QM_ASSIGN                                        ~10     ~15
         23    >   CONCAT                                           ~16     ~7, ~10
   22    24        FETCH_DIM_R                                      ~17     !0, 3
         25        TYPE_CHECK                                    2          ~17
         26      > JMPZ                                                     ~18, ->29
         27    >   QM_ASSIGN                                        ~19     ''
         28      > JMP                                                      ->38
         29    >   FETCH_DIM_R                                      ~20     !0, 3
         30        ISSET_ISEMPTY_DIM_OBJ                         0          !3, ~20
         31      > JMPZ                                                     ~21, ->36
         32    >   FETCH_DIM_R                                      ~22     !0, 3
         33        FETCH_DIM_R                                      ~23     !3, ~22
         34        QM_ASSIGN                                        ~24     ~23
         35      > JMP                                                      ->37
         36    >   QM_ASSIGN                                        ~24     '%5Bthird+not+found%5D'
         37    >   QM_ASSIGN                                        ~19     ~24
         38    >   CONCAT                                           ~25     ~16, ~19
   23    39        CONCAT                                           ~26     ~25, '%2A%2A'
         40      > RETURN                                                   ~26
   25    41*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2F7mDqd%3A18%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
200.34 ms | 1408 KiB | 16 Q