3v4l.org

run code in 300+ PHP versions simultaneously
<?php $utterance = 'This is a brown bear with 7 kids'; $template = 'This is a {color} bear with {kids} kids'; $newPattern = '/'; foreach(preg_split('/(\{.*?\})/', $template, -1, PREG_SPLIT_DELIM_CAPTURE) as $part) { if(preg_match('/^(\{.*\})$/', $part)) { $varName = trim($part, '{}'); $newPattern .= '(?P<'. preg_quote($varName) . '>.+)'; } else { $newPattern .= preg_quote($part); } } $newPattern .= '/'; echo $newPattern; echo "\n"; preg_match($newPattern, $utterance, $variables); var_dump($variables);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 10, Position 2 = 33
Branch analysis from position: 10
2 jumps found. (Code = 78) Position 1 = 11, Position 2 = 33
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 28
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 32
Branch analysis from position: 32
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
Branch analysis from position: 28
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
Branch analysis from position: 33
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 33
filename:       /in/SE5jk
function name:  (null)
number of ops:  46
compiled vars:  !0 = $utterance, !1 = $template, !2 = $newPattern, !3 = $part, !4 = $varName, !5 = $variables
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, 'This+is+a+brown+bear+with+7+kids'
    4     1        ASSIGN                                                   !1, 'This+is+a+%7Bcolor%7D+bear+with+%7Bkids%7D+kids'
    6     2        ASSIGN                                                   !2, '%2F'
    7     3        INIT_FCALL                                               'preg_split'
          4        SEND_VAL                                                 '%2F%28%5C%7B.%2A%3F%5C%7D%29%2F'
          5        SEND_VAR                                                 !1
          6        SEND_VAL                                                 -1
          7        SEND_VAL                                                 2
          8        DO_ICALL                                         $9      
          9      > FE_RESET_R                                       $10     $9, ->33
         10    > > FE_FETCH_R                                               $10, !3, ->33
    8    11    >   INIT_FCALL                                               'preg_match'
         12        SEND_VAL                                                 '%2F%5E%28%5C%7B.%2A%5C%7D%29%24%2F'
         13        SEND_VAR                                                 !3
         14        DO_ICALL                                         $11     
         15      > JMPZ                                                     $11, ->28
    9    16    >   INIT_FCALL                                               'trim'
         17        SEND_VAR                                                 !3
         18        SEND_VAL                                                 '%7B%7D'
         19        DO_ICALL                                         $12     
         20        ASSIGN                                                   !4, $12
   10    21        INIT_FCALL                                               'preg_quote'
         22        SEND_VAR                                                 !4
         23        DO_ICALL                                         $14     
         24        CONCAT                                           ~15     '%28%3FP%3C', $14
         25        CONCAT                                           ~16     ~15, '%3E.%2B%29'
         26        ASSIGN_OP                                     8          !2, ~16
    8    27      > JMP                                                      ->32
   13    28    >   INIT_FCALL                                               'preg_quote'
         29        SEND_VAR                                                 !3
         30        DO_ICALL                                         $18     
         31        ASSIGN_OP                                     8          !2, $18
    7    32    > > JMP                                                      ->10
         33    >   FE_FREE                                                  $10
   16    34        ASSIGN_OP                                     8          !2, '%2F'
   17    35        ECHO                                                     !2
   18    36        ECHO                                                     '%0A'
   19    37        INIT_FCALL                                               'preg_match'
         38        SEND_VAR                                                 !2
         39        SEND_VAR                                                 !0
         40        SEND_REF                                                 !5
         41        DO_ICALL                                                 
   20    42        INIT_FCALL                                               'var_dump'
         43        SEND_VAR                                                 !5
         44        DO_ICALL                                                 
         45      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
125.6 ms | 1009 KiB | 18 Q