3v4l.org

run code in 300+ PHP versions simultaneously
<?php $str = 'Showing results [program=for {program} programs|No pogram at all] [province=in {province}] [degree=with degree of {degree}]'; function interpolateString($message, array $context = array()) { $arrMatches = array(); $str = $message; preg_match_all("/\[(\w+)\=([^\[\]\|.*]*)?\|*([^\[\].*]*)\]/", $str, $arrMatches); $contextKeys = $arrMatches[1]; $contextCondition = array(); $contextValues = array(); $i = 0; foreach ($contextKeys as $key){ $contextCondition += array($key => $arrMatches[0][$i]); $i++;} $i = 0; foreach ($contextKeys as $key){ $value = $context[$key] != false ? 2 : 3; $contextValues += array($key => $arrMatches[$value][$i]); $i++;} foreach ($contextKeys as $key){ $str = str_replace($contextCondition[$key], $contextValues[$key], $str); } $message = $str; $replace = array(); foreach ($context as $key => $val) { $replace['{' . $key . '}'] = $val; } return strtr($message, $replace); } $arrContext = array( 'program' => 'Nursing', 'province' => false, 'degree' => false ); echo interpolateString($str, $arrContext); echo "\n";
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/qYJFK
function name:  (null)
number of ops:  9
compiled vars:  !0 = $str, !1 = $arrContext
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, 'Showing+results+%5Bprogram%3Dfor+%7Bprogram%7D+programs%7CNo+pogram+at+all%5D+%5Bprovince%3Din+%7Bprovince%7D%5D+%5Bdegree%3Dwith+degree+of+%7Bdegree%7D%5D'
   32     1        ASSIGN                                                   !1, <array>
   37     2        INIT_FCALL                                               'interpolatestring'
          3        SEND_VAR                                                 !0
          4        SEND_VAR                                                 !1
          5        DO_FCALL                                      0  $4      
          6        ECHO                                                     $4
   38     7        ECHO                                                     '%0A'
          8      > RETURN                                                   1

Function interpolatestring:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 15, Position 2 = 22
Branch analysis from position: 15
2 jumps found. (Code = 78) Position 1 = 16, Position 2 = 22
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
Branch analysis from position: 22
2 jumps found. (Code = 77) Position 1 = 25, Position 2 = 39
Branch analysis from position: 25
2 jumps found. (Code = 78) Position 1 = 26, Position 2 = 39
Branch analysis from position: 26
2 jumps found. (Code = 43) Position 1 = 29, Position 2 = 31
Branch analysis from position: 29
1 jumps found. (Code = 42) Position 1 = 32
Branch analysis from position: 32
1 jumps found. (Code = 42) Position 1 = 25
Branch analysis from position: 25
Branch analysis from position: 31
1 jumps found. (Code = 42) Position 1 = 25
Branch analysis from position: 25
Branch analysis from position: 39
2 jumps found. (Code = 77) Position 1 = 41, Position 2 = 51
Branch analysis from position: 41
2 jumps found. (Code = 78) Position 1 = 42, Position 2 = 51
Branch analysis from position: 42
1 jumps found. (Code = 42) Position 1 = 41
Branch analysis from position: 41
Branch analysis from position: 51
2 jumps found. (Code = 77) Position 1 = 55, Position 2 = 62
Branch analysis from position: 55
2 jumps found. (Code = 78) Position 1 = 56, Position 2 = 62
Branch analysis from position: 56
1 jumps found. (Code = 42) Position 1 = 55
Branch analysis from position: 55
Branch analysis from position: 62
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 62
Branch analysis from position: 51
Branch analysis from position: 39
Branch analysis from position: 22
filename:       /in/qYJFK
function name:  interpolateString
number of ops:  69
compiled vars:  !0 = $message, !1 = $context, !2 = $arrMatches, !3 = $str, !4 = $contextKeys, !5 = $contextCondition, !6 = $contextValues, !7 = $i, !8 = $key, !9 = $value, !10 = $replace, !11 = $val
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      <array>
    7     2        ASSIGN                                                   !2, <array>
    8     3        ASSIGN                                                   !3, !0
    9     4        INIT_FCALL                                               'preg_match_all'
          5        SEND_VAL                                                 '%2F%5C%5B%28%5Cw%2B%29%5C%3D%28%5B%5E%5C%5B%5C%5D%5C%7C.%2A%5D%2A%29%3F%5C%7C%2A%28%5B%5E%5C%5B%5C%5D.%2A%5D%2A%29%5C%5D%2F'
          6        SEND_VAR                                                 !3
          7        SEND_REF                                                 !2
          8        DO_ICALL                                                 
   11     9        FETCH_DIM_R                                      ~15     !2, 1
         10        ASSIGN                                                   !4, ~15
   12    11        ASSIGN                                                   !5, <array>
   13    12        ASSIGN                                                   !6, <array>
   15    13        ASSIGN                                                   !7, 0
   16    14      > FE_RESET_R                                       $20     !4, ->22
         15    > > FE_FETCH_R                                               $20, !8, ->22
         16    >   FETCH_DIM_R                                      ~21     !2, 0
         17        FETCH_DIM_R                                      ~22     ~21, !7
         18        INIT_ARRAY                                       ~23     ~22, !8
         19        ASSIGN_OP                                     1          !5, ~23
         20        PRE_INC                                                  !7
         21      > JMP                                                      ->15
         22    >   FE_FREE                                                  $20
   18    23        ASSIGN                                                   !7, 0
   19    24      > FE_RESET_R                                       $27     !4, ->39
         25    > > FE_FETCH_R                                               $27, !8, ->39
         26    >   FETCH_DIM_R                                      ~28     !1, !8
         27        BOOL                                             ~29     ~28
         28      > JMPZ                                                     ~29, ->31
         29    >   QM_ASSIGN                                        ~30     2
         30      > JMP                                                      ->32
         31    >   QM_ASSIGN                                        ~30     3
         32    >   ASSIGN                                                   !9, ~30
         33        FETCH_DIM_R                                      ~32     !2, !9
         34        FETCH_DIM_R                                      ~33     ~32, !7
         35        INIT_ARRAY                                       ~34     ~33, !8
         36        ASSIGN_OP                                     1          !6, ~34
         37        PRE_INC                                                  !7
         38      > JMP                                                      ->25
         39    >   FE_FREE                                                  $27
   21    40      > FE_RESET_R                                       $37     !4, ->51
         41    > > FE_FETCH_R                                               $37, !8, ->51
   22    42    >   INIT_FCALL                                               'str_replace'
         43        FETCH_DIM_R                                      ~38     !5, !8
         44        SEND_VAL                                                 ~38
         45        FETCH_DIM_R                                      ~39     !6, !8
         46        SEND_VAL                                                 ~39
         47        SEND_VAR                                                 !3
         48        DO_ICALL                                         $40     
         49        ASSIGN                                                   !3, $40
   21    50      > JMP                                                      ->41
         51    >   FE_FREE                                                  $37
   25    52        ASSIGN                                                   !0, !3
   26    53        ASSIGN                                                   !10, <array>
   27    54      > FE_RESET_R                                       $44     !1, ->62
         55    > > FE_FETCH_R                                       ~45     $44, !11, ->62
         56    >   ASSIGN                                                   !8, ~45
   28    57        CONCAT                                           ~47     '%7B', !8
         58        CONCAT                                           ~48     ~47, '%7D'
         59        ASSIGN_DIM                                               !10, ~48
         60        OP_DATA                                                  !11
   27    61      > JMP                                                      ->55
         62    >   FE_FREE                                                  $44
   30    63        INIT_FCALL                                               'strtr'
         64        SEND_VAR                                                 !0
         65        SEND_VAR                                                 !10
         66        DO_ICALL                                         $50     
         67      > RETURN                                                   $50
   31    68*     > RETURN                                                   null

End of function interpolatestring

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
154.49 ms | 1407 KiB | 20 Q