3v4l.org

run code in 300+ PHP versions simultaneously
<?php mb_internal_encoding('UTF-8'); $full_string = 'ĂȘtre vivant'; $match = 'vivant'; //) is ĂȘtr<strong>e viva</strong>nt echo Foo::highlightTerm($full_string, $match); class Foo{ public static function highlightTerm($full_string, $match){ $full_string_ascii = preg_replace_callback('/[\w]+/ui', array('self', 'callbackHighlightTerm'), $full_string); $match_ascii = preg_replace_callback('/[\w]+/ui', array('self', 'callbackHighlightTerm'), $match); /**/var_dump($full_string_ascii, $match_ascii); $start = stripos($full_string_ascii, $match_ascii); if($start===FALSE){ return $full_string; }else{ $length = mb_strlen($match); return htmlspecialchars( mb_substr($full_string, 0, $start)) . '<strong>' . htmlspecialchars( mb_substr($full_string, $start, $length) ) . '</strong>' . htmlspecialchars( mb_substr($full_string, $start+$length) ); } } private static function callbackHighlightTerm($matches){ return preg_replace('/[^\w]/i', '', iconv('UTF-8', 'ASCII//TRANSLIT', $matches[0])); } } ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/aCMfF
function name:  (null)
number of ops:  11
compiled vars:  !0 = $full_string, !1 = $match
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   INIT_FCALL                                               'mb_internal_encoding'
          1        SEND_VAL                                                 'UTF-8'
          2        DO_ICALL                                                 
    5     3        ASSIGN                                                   !0, '%C3%AAtre+vivant'
    6     4        ASSIGN                                                   !1, 'vivant'
    9     5        INIT_STATIC_METHOD_CALL                                  'Foo', 'highlightTerm'
          6        SEND_VAR_EX                                              !0
          7        SEND_VAR_EX                                              !1
          8        DO_FCALL                                      0  $5      
          9        ECHO                                                     $5
   37    10      > RETURN                                                   1

Class Foo:
Function highlightterm:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 25, Position 2 = 27
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 27
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/aCMfF
function name:  highlightTerm
number of ops:  61
compiled vars:  !0 = $full_string, !1 = $match, !2 = $full_string_ascii, !3 = $match_ascii, !4 = $start, !5 = $length
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   13     2        INIT_FCALL                                               'preg_replace_callback'
          3        SEND_VAL                                                 '%2F%5B%5Cw%5D%2B%2Fui'
          4        SEND_VAL                                                 <array>
          5        SEND_VAR                                                 !0
          6        DO_ICALL                                         $6      
          7        ASSIGN                                                   !2, $6
   14     8        INIT_FCALL                                               'preg_replace_callback'
          9        SEND_VAL                                                 '%2F%5B%5Cw%5D%2B%2Fui'
         10        SEND_VAL                                                 <array>
         11        SEND_VAR                                                 !1
         12        DO_ICALL                                         $8      
         13        ASSIGN                                                   !3, $8
   15    14        INIT_FCALL                                               'var_dump'
         15        SEND_VAR                                                 !2
         16        SEND_VAR                                                 !3
         17        DO_ICALL                                                 
   17    18        INIT_FCALL                                               'stripos'
         19        SEND_VAR                                                 !2
         20        SEND_VAR                                                 !3
         21        DO_ICALL                                         $11     
         22        ASSIGN                                                   !4, $11
   19    23        TYPE_CHECK                                    4          !4
         24      > JMPZ                                                     ~13, ->27
   20    25    > > RETURN                                                   !0
         26*       JMP                                                      ->60
   22    27    >   INIT_FCALL                                               'mb_strlen'
         28        SEND_VAR                                                 !1
         29        DO_ICALL                                         $14     
         30        ASSIGN                                                   !5, $14
   25    31        INIT_FCALL                                               'htmlspecialchars'
         32        INIT_FCALL                                               'mb_substr'
         33        SEND_VAR                                                 !0
         34        SEND_VAL                                                 0
         35        SEND_VAR                                                 !4
         36        DO_ICALL                                         $16     
         37        SEND_VAR                                                 $16
         38        DO_ICALL                                         $17     
   26    39        CONCAT                                           ~18     $17, '%3Cstrong%3E'
         40        INIT_FCALL                                               'htmlspecialchars'
         41        INIT_FCALL                                               'mb_substr'
         42        SEND_VAR                                                 !0
         43        SEND_VAR                                                 !4
         44        SEND_VAR                                                 !5
         45        DO_ICALL                                         $19     
         46        SEND_VAR                                                 $19
         47        DO_ICALL                                         $20     
         48        CONCAT                                           ~21     ~18, $20
         49        CONCAT                                           ~22     ~21, '%3C%2Fstrong%3E'
   27    50        INIT_FCALL                                               'htmlspecialchars'
         51        INIT_FCALL                                               'mb_substr'
         52        SEND_VAR                                                 !0
         53        ADD                                              ~23     !4, !5
         54        SEND_VAL                                                 ~23
         55        DO_ICALL                                         $24     
         56        SEND_VAR                                                 $24
         57        DO_ICALL                                         $25     
         58        CONCAT                                           ~26     ~22, $25
         59      > RETURN                                                   ~26
   29    60*     > RETURN                                                   null

End of function highlightterm

Function callbackhighlightterm:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/aCMfF
function name:  callbackHighlightTerm
number of ops:  15
compiled vars:  !0 = $matches
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   32     0  E >   RECV                                             !0      
   33     1        INIT_FCALL                                               'preg_replace'
          2        SEND_VAL                                                 '%2F%5B%5E%5Cw%5D%2Fi'
          3        SEND_VAL                                                 ''
          4        INIT_FCALL_BY_NAME                                       'iconv'
          5        SEND_VAL_EX                                              'UTF-8'
          6        SEND_VAL_EX                                              'ASCII%2F%2FTRANSLIT'
          7        CHECK_FUNC_ARG                                           
          8        FETCH_DIM_FUNC_ARG                               $1      !0, 0
          9        SEND_FUNC_ARG                                            $1
         10        DO_FCALL                                      0  $2      
         11        SEND_VAR                                                 $2
         12        DO_ICALL                                         $3      
         13      > RETURN                                                   $3
   34    14*     > RETURN                                                   null

End of function callbackhighlightterm

End of class Foo.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
169.14 ms | 1396 KiB | 32 Q