3v4l.org

run code in 300+ PHP versions simultaneously
<?php function highlight($needle, $haystack, $respect, $highlightStart, $highlightEnd) { $replacer = static function ($matches) use ($respect, $highlightStart, $highlightEnd) { return $highlightStart . preg_replace('([^' . $respect . ']+)', $highlightEnd . '$0' . $highlightStart, $matches[0]) . $highlightEnd; }; $needle = str_split($needle); foreach ($needle as &$l) { $l = preg_quote($l); } unset($l); $needle = implode('[^' . $respect . ']*', $needle); return preg_replace_callback('(' . $needle . ')', $replacer, $haystack); } echo highlight('1234', '(123) 456-7890', '0-9', '<b>', '</b>');
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/sZdbJ
function name:  (null)
number of ops:  9
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   INIT_FCALL                                               'highlight'
          1        SEND_VAL                                                 '1234'
          2        SEND_VAL                                                 '%28123%29+456-7890'
          3        SEND_VAL                                                 '0-9'
          4        SEND_VAL                                                 '%3Cb%3E'
          5        SEND_VAL                                                 '%3C%2Fb%3E'
          6        DO_FCALL                                      0  $0      
          7        ECHO                                                     $0
          8      > RETURN                                                   1

Function highlight:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 125) Position 1 = 15, Position 2 = 21
Branch analysis from position: 15
2 jumps found. (Code = 126) Position 1 = 16, Position 2 = 21
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 21
filename:       /in/sZdbJ
function name:  highlight
number of ops:  39
compiled vars:  !0 = $needle, !1 = $haystack, !2 = $respect, !3 = $highlightStart, !4 = $highlightEnd, !5 = $replacer, !6 = $l
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
          3        RECV                                             !3      
          4        RECV                                             !4      
    4     5        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FsZdbJ%3A4%240'
          6        BIND_LEXICAL                                             ~7, !2
          7        BIND_LEXICAL                                             ~7, !3
          8        BIND_LEXICAL                                             ~7, !4
          9        ASSIGN                                                   !5, ~7
   11    10        INIT_FCALL                                               'str_split'
         11        SEND_VAR                                                 !0
         12        DO_ICALL                                         $9      
         13        ASSIGN                                                   !0, $9
   12    14      > FE_RESET_RW                                      $11     !0, ->21
         15    > > FE_FETCH_RW                                              $11, !6, ->21
   13    16    >   INIT_FCALL                                               'preg_quote'
         17        SEND_VAR                                                 !6
         18        DO_ICALL                                         $12     
         19        ASSIGN                                                   !6, $12
   12    20      > JMP                                                      ->15
         21    >   FE_FREE                                                  $11
   15    22        UNSET_CV                                                 !6
   16    23        INIT_FCALL                                               'implode'
         24        CONCAT                                           ~14     '%5B%5E', !2
         25        CONCAT                                           ~15     ~14, '%5D%2A'
         26        SEND_VAL                                                 ~15
         27        SEND_VAR                                                 !0
         28        DO_ICALL                                         $16     
         29        ASSIGN                                                   !0, $16
   17    30        INIT_FCALL                                               'preg_replace_callback'
         31        CONCAT                                           ~18     '%28', !0
         32        CONCAT                                           ~19     ~18, '%29'
         33        SEND_VAL                                                 ~19
         34        SEND_VAR                                                 !5
         35        SEND_VAR                                                 !1
         36        DO_ICALL                                         $20     
         37      > RETURN                                                   $20
   18    38*     > RETURN                                                   null

End of function highlight

Function %00%7Bclosure%7D%2Fin%2FsZdbJ%3A4%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/sZdbJ
function name:  {closure}
number of ops:  18
compiled vars:  !0 = $matches, !1 = $respect, !2 = $highlightStart, !3 = $highlightEnd
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
          2        BIND_STATIC                                              !2
          3        BIND_STATIC                                              !3
    7     4        INIT_FCALL                                               'preg_replace'
          5        CONCAT                                           ~4      '%28%5B%5E', !1
          6        CONCAT                                           ~5      ~4, '%5D%2B%29'
          7        SEND_VAL                                                 ~5
          8        CONCAT                                           ~6      !3, '%240'
          9        CONCAT                                           ~7      ~6, !2
         10        SEND_VAL                                                 ~7
         11        FETCH_DIM_R                                      ~8      !0, 0
         12        SEND_VAL                                                 ~8
         13        DO_ICALL                                         $9      
         14        CONCAT                                           ~10     !2, $9
    8    15        CONCAT                                           ~11     ~10, !3
         16      > RETURN                                                   ~11
    9    17*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FsZdbJ%3A4%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
165.14 ms | 1403 KiB | 24 Q