3v4l.org

run code in 300+ PHP versions simultaneously
<?php function highlight($text, $words) { preg_match_all ( '~[\w\'\"]+~', $words, $m ); if (! $m) return $text; $re = '~\\b(' . implode ( '|', $m [0] ) . ')\\b~i'; return preg_replace ( $re, '<em>$0</em>', $text ); } $text = "this is Mechanic's test"; $word = "Mechanic's"; echo highlight($text,$word); $text = 'this is Mechanic"s test'; $word = 'Mechanic"s'; echo "\n".highlight($text,$word); $text = 'this is Mechanics test'; $word = 'Mech'; echo "\n".highlight($text,$word); echo str_replace($words,"<em>$words</em>",$text) ;
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/crSJB
function name:  (null)
number of ops:  33
compiled vars:  !0 = $text, !1 = $word, !2 = $words
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   ASSIGN                                                   !0, 'this+is+Mechanic%27s+test'
   12     1        ASSIGN                                                   !1, 'Mechanic%27s'
   14     2        INIT_FCALL                                               'highlight'
          3        SEND_VAR                                                 !0
          4        SEND_VAR                                                 !1
          5        DO_FCALL                                      0  $5      
          6        ECHO                                                     $5
   16     7        ASSIGN                                                   !0, 'this+is+Mechanic%22s+test'
   17     8        ASSIGN                                                   !1, 'Mechanic%22s'
   18     9        INIT_FCALL                                               'highlight'
         10        SEND_VAR                                                 !0
         11        SEND_VAR                                                 !1
         12        DO_FCALL                                      0  $8      
         13        CONCAT                                           ~9      '%0A', $8
         14        ECHO                                                     ~9
   20    15        ASSIGN                                                   !0, 'this+is+Mechanics+test'
   21    16        ASSIGN                                                   !1, 'Mech'
   22    17        INIT_FCALL                                               'highlight'
         18        SEND_VAR                                                 !0
         19        SEND_VAR                                                 !1
         20        DO_FCALL                                      0  $12     
         21        CONCAT                                           ~13     '%0A', $12
         22        ECHO                                                     ~13
   25    23        INIT_FCALL                                               'str_replace'
         24        SEND_VAR                                                 !2
         25        ROPE_INIT                                     3  ~15     '%3Cem%3E'
         26        ROPE_ADD                                      1  ~15     ~15, !2
         27        ROPE_END                                      2  ~14     ~15, '%3C%2Fem%3E'
         28        SEND_VAL                                                 ~14
         29        SEND_VAR                                                 !0
         30        DO_ICALL                                         $17     
         31        ECHO                                                     $17
         32      > RETURN                                                   1

Function highlight:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 10
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/crSJB
function name:  highlight
number of ops:  25
compiled vars:  !0 = $text, !1 = $words, !2 = $m, !3 = $re
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    3     2        INIT_FCALL                                               'preg_match_all'
          3        SEND_VAL                                                 '%7E%5B%5Cw%27%5C%22%5D%2B%7E'
          4        SEND_VAR                                                 !1
          5        SEND_REF                                                 !2
          6        DO_ICALL                                                 
    4     7        BOOL_NOT                                         ~5      !2
          8      > JMPZ                                                     ~5, ->10
    5     9    > > RETURN                                                   !0
    6    10    >   INIT_FCALL                                               'implode'
         11        SEND_VAL                                                 '%7C'
         12        FETCH_DIM_R                                      ~6      !2, 0
         13        SEND_VAL                                                 ~6
         14        DO_ICALL                                         $7      
         15        CONCAT                                           ~8      '%7E%5Cb%28', $7
         16        CONCAT                                           ~9      ~8, '%29%5Cb%7Ei'
         17        ASSIGN                                                   !3, ~9
    7    18        INIT_FCALL                                               'preg_replace'
         19        SEND_VAR                                                 !3
         20        SEND_VAL                                                 '%3Cem%3E%240%3C%2Fem%3E'
         21        SEND_VAR                                                 !0
         22        DO_ICALL                                         $11     
         23      > RETURN                                                   $11
    8    24*     > RETURN                                                   null

End of function highlight

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
146.35 ms | 1394 KiB | 24 Q