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); for ($i=0; $i<=count($arrMatches[1])-1;$i++) { if ($arrContext[$arrMatches[1][$i]] !== false) { $str = strstr($arrMatches[0][$i], $arrMatches[2][$i]); }else{ $str = strstr($arrMatches[0][$i], $arrMatches[2][$i]); } } echo $str;
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 36
Branch analysis from position: 36
2 jumps found. (Code = 44) Position 1 = 41, Position 2 = 11
Branch analysis from position: 41
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 26
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 35
Branch analysis from position: 35
2 jumps found. (Code = 44) Position 1 = 41, Position 2 = 11
Branch analysis from position: 41
Branch analysis from position: 11
Branch analysis from position: 26
2 jumps found. (Code = 44) Position 1 = 41, Position 2 = 11
Branch analysis from position: 41
Branch analysis from position: 11
filename:       /in/pHk12
function name:  (null)
number of ops:  43
compiled vars:  !0 = $str, !1 = $arrContext, !2 = $arrMatches, !3 = $i
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        ASSIGN                                                   !3, 0
         10      > JMP                                                      ->36
   24    11    >   FETCH_DIM_R                                      ~9      !2, 1
         12        FETCH_DIM_R                                      ~10     ~9, !3
         13        FETCH_DIM_R                                      ~11     !1, ~10
         14        TYPE_CHECK                                  1018          ~11
         15      > JMPZ                                                     ~12, ->26
   25    16    >   INIT_FCALL                                               'strstr'
         17        FETCH_DIM_R                                      ~13     !2, 0
         18        FETCH_DIM_R                                      ~14     ~13, !3
         19        SEND_VAL                                                 ~14
         20        FETCH_DIM_R                                      ~15     !2, 2
         21        FETCH_DIM_R                                      ~16     ~15, !3
         22        SEND_VAL                                                 ~16
         23        DO_ICALL                                         $17     
         24        ASSIGN                                                   !0, $17
         25      > JMP                                                      ->35
   27    26    >   INIT_FCALL                                               'strstr'
         27        FETCH_DIM_R                                      ~19     !2, 0
         28        FETCH_DIM_R                                      ~20     ~19, !3
         29        SEND_VAL                                                 ~20
         30        FETCH_DIM_R                                      ~21     !2, 2
         31        FETCH_DIM_R                                      ~22     ~21, !3
         32        SEND_VAL                                                 ~22
         33        DO_ICALL                                         $23     
         34        ASSIGN                                                   !0, $23
   23    35    >   PRE_INC                                                  !3
         36    >   FETCH_DIM_R                                      ~26     !2, 1
         37        COUNT                                            ~27     ~26
         38        SUB                                              ~28     ~27, 1
         39        IS_SMALLER_OR_EQUAL                                      !3, ~28
         40      > JMPNZ                                                    ~29, ->11
   30    41    >   ECHO                                                     !0
         42      > 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/pHk12
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:
160.52 ms | 1392 KiB | 19 Q