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()) { $replace = array(); foreach ($context as $key => $val) { $replace['{' . $key . '}'] = $val; } return strtr($message, $replace); } $arrContext = array( 'program' => 'Nursing', 'province' => 'Ontario', 'degree' => false ); //echo interpolateString($str, $arrContext); echo "\n"; $arrMatches = array(); preg_match_all("/\[(\w+)\=([^\[\]\|.*]*)?\|*([^\[\].*]*)\]/", $str, $arrMatches); $contextKeys = $arrMatches[1]; $contextCondition = array(); $i = 0; foreach ($contextKeys as $key){ $contextCondition[] = array($key => $arrMatches[0][$i]); $i++; } foreach ($contextKeys as $key){ echo "{$key} -> {$contextCondition[$key]}\n"; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 14, Position 2 = 22
Branch analysis from position: 14
2 jumps found. (Code = 78) Position 1 = 15, Position 2 = 22
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
Branch analysis from position: 22
2 jumps found. (Code = 77) Position 1 = 24, Position 2 = 32
Branch analysis from position: 24
2 jumps found. (Code = 78) Position 1 = 25, Position 2 = 32
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 24
Branch analysis from position: 24
Branch analysis from position: 32
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 32
Branch analysis from position: 22
filename:       /in/5pSsR
function name:  (null)
number of ops:  34
compiled vars:  !0 = $str, !1 = $arrContext, !2 = $arrMatches, !3 = $contextKeys, !4 = $contextCondition, !5 = $i, !6 = $key
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'
   12     1        ASSIGN                                                   !1, <array>
   18     2        ECHO                                                     '%0A'
   20     3        ASSIGN                                                   !2, <array>
   21     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                                                 !0
          7        SEND_REF                                                 !2
          8        DO_ICALL                                                 
   23     9        FETCH_DIM_R                                      ~11     !2, 1
         10        ASSIGN                                                   !3, ~11
   24    11        ASSIGN                                                   !4, <array>
   26    12        ASSIGN                                                   !5, 0
   27    13      > FE_RESET_R                                       $15     !3, ->22
         14    > > FE_FETCH_R                                               $15, !6, ->22
   28    15    >   FETCH_DIM_R                                      ~17     !2, 0
         16        FETCH_DIM_R                                      ~18     ~17, !5
         17        INIT_ARRAY                                       ~19     ~18, !6
         18        ASSIGN_DIM                                               !4
         19        OP_DATA                                                  ~19
   29    20        PRE_INC                                                  !5
   27    21      > JMP                                                      ->14
         22    >   FE_FREE                                                  $15
   32    23      > FE_RESET_R                                       $21     !3, ->32
         24    > > FE_FETCH_R                                               $21, !6, ->32
   33    25    >   ROPE_INIT                                     4  ~24     !6
         26        ROPE_ADD                                      1  ~24     ~24, '+-%3E+'
         27        FETCH_DIM_R                                      ~22     !4, !6
         28        ROPE_ADD                                      2  ~24     ~24, ~22
         29        ROPE_END                                      3  ~23     ~24, '%0A'
         30        ECHO                                                     ~23
   32    31      > JMP                                                      ->24
         32    >   FE_FREE                                                  $21
   34    33      > RETURN                                                   1

Function interpolatestring:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 11
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 11
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
filename:       /in/5pSsR
function name:  interpolateString
number of ops:  18
compiled vars:  !0 = $message, !1 = $context, !2 = $replace, !3 = $val, !4 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      <array>
    5     2        ASSIGN                                                   !2, <array>
    6     3      > FE_RESET_R                                       $6      !1, ->11
          4    > > FE_FETCH_R                                       ~7      $6, !3, ->11
          5    >   ASSIGN                                                   !4, ~7
    7     6        CONCAT                                           ~9      '%7B', !4
          7        CONCAT                                           ~10     ~9, '%7D'
          8        ASSIGN_DIM                                               !2, ~10
          9        OP_DATA                                                  !3
    6    10      > JMP                                                      ->4
         11    >   FE_FREE                                                  $6
    9    12        INIT_FCALL                                               'strtr'
         13        SEND_VAR                                                 !0
         14        SEND_VAR                                                 !2
         15        DO_ICALL                                         $12     
         16      > RETURN                                                   $12
   10    17*     > RETURN                                                   null

End of function interpolatestring

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
156.74 ms | 1392 KiB | 17 Q