3v4l.org

run code in 300+ PHP versions simultaneously
<?php $title = "服务员服务服务员服务员"; $term = "服务,服务员"; $termKey = explode(',' , $term); $tempTitle = ''; $strlength = strlen($title); if($title && !empty($termKey) && is_array($termKey)){ $newTitle = $title; $cur = count($termKey) - 1; //倒叙匹配 for($i=$cur;$i >= 0 ;--$i) { if($termKey[$i] && strstr($newTitle , $termKey[$i])) { $position = mb_strrpos($newTitle,'</span>'); if($position){ $tempTitle .= mb_substr($newTitle , 0 , $position , 'UTF-8'); } $str = '<span class="fc-red">'.$termKey[$i].'</span>'; $newTitle = preg_replace("/$termKey[$i]/i" , $str , mb_substr($newTitle , $position , $strlength , 'UTF-8'),1); } } $newTitle = $tempTitle.$newTitle; echo $newTitle; }else echo $title;
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 11, Position 2 = 14
Branch analysis from position: 11
2 jumps found. (Code = 46) Position 1 = 15, Position 2 = 17
Branch analysis from position: 15
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 74
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 68
Branch analysis from position: 68
2 jumps found. (Code = 44) Position 1 = 70, Position 2 = 24
Branch analysis from position: 70
1 jumps found. (Code = 42) Position 1 = 75
Branch analysis from position: 75
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 24
2 jumps found. (Code = 46) Position 1 = 26, Position 2 = 32
Branch analysis from position: 26
2 jumps found. (Code = 43) Position 1 = 33, Position 2 = 67
Branch analysis from position: 33
2 jumps found. (Code = 43) Position 1 = 39, Position 2 = 46
Branch analysis from position: 39
2 jumps found. (Code = 44) Position 1 = 70, Position 2 = 24
Branch analysis from position: 70
Branch analysis from position: 24
Branch analysis from position: 46
Branch analysis from position: 67
Branch analysis from position: 32
Branch analysis from position: 74
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
Branch analysis from position: 14
filename:       /in/fUtfD
function name:  (null)
number of ops:  76
compiled vars:  !0 = $title, !1 = $term, !2 = $termKey, !3 = $tempTitle, !4 = $strlength, !5 = $newTitle, !6 = $cur, !7 = $i, !8 = $position, !9 = $str
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, '%E6%9C%8D%E5%8A%A1%E5%91%98%E6%9C%8D%E5%8A%A1%E6%9C%8D%E5%8A%A1%E5%91%98%E6%9C%8D%E5%8A%A1%E5%91%98'
    3     1        ASSIGN                                                   !1, '%E6%9C%8D%E5%8A%A1%2C%E6%9C%8D%E5%8A%A1%E5%91%98'
    4     2        INIT_FCALL                                               'explode'
          3        SEND_VAL                                                 '%2C'
          4        SEND_VAR                                                 !1
          5        DO_ICALL                                         $12     
          6        ASSIGN                                                   !2, $12
    5     7        ASSIGN                                                   !3, ''
    6     8        STRLEN                                           ~15     !0
          9        ASSIGN                                                   !4, ~15
    7    10      > JMPZ_EX                                          ~17     !0, ->14
         11    >   ISSET_ISEMPTY_CV                                 ~18     !2
         12        BOOL_NOT                                         ~19     ~18
         13        BOOL                                             ~17     ~19
         14    > > JMPZ_EX                                          ~17     ~17, ->17
         15    >   TYPE_CHECK                                  128  ~20     !2
         16        BOOL                                             ~17     ~20
         17    > > JMPZ                                                     ~17, ->74
    8    18    >   ASSIGN                                                   !5, !0
    9    19        COUNT                                            ~22     !2
         20        SUB                                              ~23     ~22, 1
         21        ASSIGN                                                   !6, ~23
   10    22        ASSIGN                                                   !7, !6
         23      > JMP                                                      ->68
   11    24    >   FETCH_DIM_R                                      ~26     !2, !7
         25      > JMPZ_EX                                          ~26     ~26, ->32
         26    >   INIT_FCALL                                               'strstr'
         27        SEND_VAR                                                 !5
         28        FETCH_DIM_R                                      ~27     !2, !7
         29        SEND_VAL                                                 ~27
         30        DO_ICALL                                         $28     
         31        BOOL                                             ~26     $28
         32    > > JMPZ                                                     ~26, ->67
   12    33    >   INIT_FCALL                                               'mb_strrpos'
         34        SEND_VAR                                                 !5
         35        SEND_VAL                                                 '%3C%2Fspan%3E'
         36        DO_ICALL                                         $29     
         37        ASSIGN                                                   !8, $29
   13    38      > JMPZ                                                     !8, ->46
   14    39    >   INIT_FCALL                                               'mb_substr'
         40        SEND_VAR                                                 !5
         41        SEND_VAL                                                 0
         42        SEND_VAR                                                 !8
         43        SEND_VAL                                                 'UTF-8'
         44        DO_ICALL                                         $31     
         45        ASSIGN_OP                                     8          !3, $31
   16    46    >   FETCH_DIM_R                                      ~33     !2, !7
         47        CONCAT                                           ~34     '%3Cspan+class%3D%22fc-red%22%3E', ~33
         48        CONCAT                                           ~35     ~34, '%3C%2Fspan%3E'
         49        ASSIGN                                                   !9, ~35
   17    50        INIT_FCALL                                               'preg_replace'
         51        ROPE_INIT                                     3  ~39     '%2F'
         52        FETCH_DIM_R                                      ~37     !2, !7
         53        ROPE_ADD                                      1  ~39     ~39, ~37
         54        ROPE_END                                      2  ~38     ~39, '%2Fi'
         55        SEND_VAL                                                 ~38
         56        SEND_VAR                                                 !9
         57        INIT_FCALL                                               'mb_substr'
         58        SEND_VAR                                                 !5
         59        SEND_VAR                                                 !8
         60        SEND_VAR                                                 !4
         61        SEND_VAL                                                 'UTF-8'
         62        DO_ICALL                                         $41     
         63        SEND_VAR                                                 $41
         64        SEND_VAL                                                 1
         65        DO_ICALL                                         $42     
         66        ASSIGN                                                   !5, $42
   10    67    >   PRE_DEC                                                  !7
         68    >   IS_SMALLER_OR_EQUAL                                      0, !7
         69      > JMPNZ                                                    ~45, ->24
   20    70    >   CONCAT                                           ~46     !3, !5
         71        ASSIGN                                                   !5, ~46
   21    72        ECHO                                                     !5
         73      > JMP                                                      ->75
   23    74    >   ECHO                                                     !0
         75    > > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
157.52 ms | 1392 KiB | 23 Q