3v4l.org

run code in 300+ PHP versions simultaneously
<?php function highlight($text, $words) { preg_match_all ( '~[a-zA-Z_\']?~', $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 "\n".str_replace($word,"<em>$word</em>",$text) ;
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/EF0oJ
function name:  (null)
number of ops:  24
compiled vars:  !0 = $text, !1 = $word
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  $4      
          6        ECHO                                                     $4
   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  $7      
         13        CONCAT                                           ~8      '%0A', $7
         14        ECHO                                                     ~8
   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  $11     
         21        CONCAT                                           ~12     '%0A', $11
         22        ECHO                                                     ~12
   25    23      > 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/EF0oJ
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%5Ba-zA-Z_%27%5D%3F%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:
163.09 ms | 943 KiB | 23 Q