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); $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/KTkqf
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
   36    10      > RETURN                                                   1

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

End of function callbackhighlightterm

End of class Foo.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
167.41 ms | 1404 KiB | 27 Q