3v4l.org

run code in 300+ PHP versions simultaneously
<?php $str = '^4Hello World ^5Foo^8Bar'; $colorMap = array( '000000', // 0 'ff0000', // 1 '00ff00', // 2 '00ff00', // 3 '00ff00', // 4 '00ff00', // 5 '00ff00', // 6 '00ff00', // 7 '00ff00', // 8 ); $parts = preg_split('/\^(\d)/', $str, -1, PREG_SPLIT_NO_EMPTY + PREG_SPLIT_DELIM_CAPTURE); $result = ''; r($parts); foreach($parts as $idx => $part) if((($idx % 2) === 0) && isset($colorMap[(int)$part])) $result .= sprintf('<span style="color:#%s">%s</span>', $colorMap[(int)$part], $parts[$idx + 1]); print $result;
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 14, Position 2 = 34
Branch analysis from position: 14
2 jumps found. (Code = 78) Position 1 = 15, Position 2 = 34
Branch analysis from position: 15
2 jumps found. (Code = 46) Position 1 = 19, Position 2 = 22
Branch analysis from position: 19
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 33
Branch analysis from position: 23
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
Branch analysis from position: 33
Branch analysis from position: 22
Branch analysis from position: 34
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 34
filename:       /in/9GHEd
function name:  (null)
number of ops:  37
compiled vars:  !0 = $str, !1 = $colorMap, !2 = $parts, !3 = $result, !4 = $part, !5 = $idx
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   ASSIGN                                                   !0, '%5E4Hello+World+%5E5Foo%5E8Bar'
    5     1        ASSIGN                                                   !1, <array>
   18     2        INIT_FCALL                                               'preg_split'
          3        SEND_VAL                                                 '%2F%5C%5E%28%5Cd%29%2F'
          4        SEND_VAR                                                 !0
          5        SEND_VAL                                                 -1
          6        SEND_VAL                                                 3
          7        DO_ICALL                                         $8      
          8        ASSIGN                                                   !2, $8
   19     9        ASSIGN                                                   !3, ''
   20    10        INIT_FCALL_BY_NAME                                       'r'
         11        SEND_VAR_EX                                              !2
         12        DO_FCALL                                      0          
   21    13      > FE_RESET_R                                       $12     !2, ->34
         14    > > FE_FETCH_R                                       ~13     $12, !4, ->34
         15    >   ASSIGN                                                   !5, ~13
   22    16        MOD                                              ~15     !5, 2
         17        IS_IDENTICAL                                     ~16     ~15, 0
         18      > JMPZ_EX                                          ~16     ~16, ->22
         19    >   CAST                                          4  ~17     !4
         20        ISSET_ISEMPTY_DIM_OBJ                         0  ~18     !1, ~17
         21        BOOL                                             ~16     ~18
         22    > > JMPZ                                                     ~16, ->33
   23    23    >   INIT_FCALL                                               'sprintf'
         24        SEND_VAL                                                 '%3Cspan+style%3D%22color%3A%23%25s%22%3E%25s%3C%2Fspan%3E'
         25        CAST                                          4  ~19     !4
         26        FETCH_DIM_R                                      ~20     !1, ~19
         27        SEND_VAL                                                 ~20
         28        ADD                                              ~21     !5, 1
         29        FETCH_DIM_R                                      ~22     !2, ~21
         30        SEND_VAL                                                 ~22
         31        DO_ICALL                                         $23     
         32        ASSIGN_OP                                     8          !3, $23
   21    33    > > JMP                                                      ->14
         34    >   FE_FREE                                                  $12
   25    35        ECHO                                                     !3
         36      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
152.41 ms | 1400 KiB | 17 Q