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'); echo $position;die; } $str = '<span class="fc-red">'.$termKey[$i].'</span>'; $jieduan=mb_substr($newTitle , $position , $strlength , 'UTF-8'); echo '---'.$jieduan.'----'; $newTitle = preg_replace("/$termKey[$i]/i" , $str , $jieduan ,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 = 80
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 74
Branch analysis from position: 74
2 jumps found. (Code = 44) Position 1 = 76, Position 2 = 24
Branch analysis from position: 76
1 jumps found. (Code = 42) Position 1 = 81
Branch analysis from position: 81
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 = 73
Branch analysis from position: 33
2 jumps found. (Code = 43) Position 1 = 39, Position 2 = 48
Branch analysis from position: 39
1 jumps found. (Code = 79) Position 1 = -2
Branch analysis from position: 48
2 jumps found. (Code = 44) Position 1 = 76, Position 2 = 24
Branch analysis from position: 76
Branch analysis from position: 24
Branch analysis from position: 73
Branch analysis from position: 32
Branch analysis from position: 80
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
Branch analysis from position: 14
filename:       /in/rd4r6
function name:  (null)
number of ops:  82
compiled vars:  !0 = $title, !1 = $term, !2 = $termKey, !3 = $tempTitle, !4 = $strlength, !5 = $newTitle, !6 = $cur, !7 = $i, !8 = $position, !9 = $str, !10 = $jieduan
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%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                                         $13     
          6        ASSIGN                                                   !2, $13
    5     7        ASSIGN                                                   !3, ''
    6     8        STRLEN                                           ~16     !0
          9        ASSIGN                                                   !4, ~16
    7    10      > JMPZ_EX                                          ~18     !0, ->14
         11    >   ISSET_ISEMPTY_CV                                 ~19     !2
         12        BOOL_NOT                                         ~20     ~19
         13        BOOL                                             ~18     ~20
         14    > > JMPZ_EX                                          ~18     ~18, ->17
         15    >   TYPE_CHECK                                  128  ~21     !2
         16        BOOL                                             ~18     ~21
         17    > > JMPZ                                                     ~18, ->80
    8    18    >   ASSIGN                                                   !5, !0
    9    19        COUNT                                            ~23     !2
         20        SUB                                              ~24     ~23, 1
         21        ASSIGN                                                   !6, ~24
   10    22        ASSIGN                                                   !7, !6
         23      > JMP                                                      ->74
   11    24    >   FETCH_DIM_R                                      ~27     !2, !7
         25      > JMPZ_EX                                          ~27     ~27, ->32
         26    >   INIT_FCALL                                               'strstr'
         27        SEND_VAR                                                 !5
         28        FETCH_DIM_R                                      ~28     !2, !7
         29        SEND_VAL                                                 ~28
         30        DO_ICALL                                         $29     
         31        BOOL                                             ~27     $29
         32    > > JMPZ                                                     ~27, ->73
   12    33    >   INIT_FCALL                                               'mb_strrpos'
         34        SEND_VAR                                                 !5
         35        SEND_VAL                                                 '%3C%2Fspan%3E'
         36        DO_ICALL                                         $30     
         37        ASSIGN                                                   !8, $30
   13    38      > JMPZ                                                     !8, ->48
   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                                         $32     
         45        ASSIGN_OP                                     8          !3, $32
   15    46        ECHO                                                     !8
         47      > EXIT                                                     
   17    48    >   FETCH_DIM_R                                      ~34     !2, !7
         49        CONCAT                                           ~35     '%3Cspan+class%3D%22fc-red%22%3E', ~34
         50        CONCAT                                           ~36     ~35, '%3C%2Fspan%3E'
         51        ASSIGN                                                   !9, ~36
   18    52        INIT_FCALL                                               'mb_substr'
         53        SEND_VAR                                                 !5
         54        SEND_VAR                                                 !8
         55        SEND_VAR                                                 !4
         56        SEND_VAL                                                 'UTF-8'
         57        DO_ICALL                                         $38     
         58        ASSIGN                                                   !10, $38
   19    59        CONCAT                                           ~40     '---', !10
         60        CONCAT                                           ~41     ~40, '----'
         61        ECHO                                                     ~41
   20    62        INIT_FCALL                                               'preg_replace'
         63        ROPE_INIT                                     3  ~44     '%2F'
         64        FETCH_DIM_R                                      ~42     !2, !7
         65        ROPE_ADD                                      1  ~44     ~44, ~42
         66        ROPE_END                                      2  ~43     ~44, '%2Fi'
         67        SEND_VAL                                                 ~43
         68        SEND_VAR                                                 !9
         69        SEND_VAR                                                 !10
         70        SEND_VAL                                                 1
         71        DO_ICALL                                         $46     
         72        ASSIGN                                                   !5, $46
   10    73    >   PRE_DEC                                                  !7
         74    >   IS_SMALLER_OR_EQUAL                                      0, !7
         75      > JMPNZ                                                    ~49, ->24
   23    76    >   CONCAT                                           ~50     !3, !5
         77        ASSIGN                                                   !5, ~50
   24    78        ECHO                                                     !5
         79      > JMP                                                      ->81
   26    80    >   ECHO                                                     !0
         81    > > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
155.18 ms | 1396 KiB | 23 Q