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' => '0' ); echo interpolateString($str, $arrContext); $pattern = 's/\[.*\]/g'; $replacement = '_'; $subject = $str; echo preg_replace_all($pattern, $replacement, $subject);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/39mUX
function name:  (null)
number of ops:  17
compiled vars:  !0 = $str, !1 = $arrContext, !2 = $pattern, !3 = $replacement, !4 = $subject
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>
   17     2        INIT_FCALL                                               'interpolatestring'
          3        SEND_VAR                                                 !0
          4        SEND_VAR                                                 !1
          5        DO_FCALL                                      0  $7      
          6        ECHO                                                     $7
   19     7        ASSIGN                                                   !2, 's%2F%5C%5B.%2A%5C%5D%2Fg'
   20     8        ASSIGN                                                   !3, '_'
   21     9        ASSIGN                                                   !4, !0
   22    10        INIT_FCALL_BY_NAME                                       'preg_replace_all'
         11        SEND_VAR_EX                                              !2
         12        SEND_VAR_EX                                              !3
         13        SEND_VAR_EX                                              !4
         14        DO_FCALL                                      0  $11     
         15        ECHO                                                     $11
         16      > 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/39mUX
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:
163.27 ms | 1402 KiB | 16 Q