3v4l.org

run code in 300+ PHP versions simultaneously
<?php function getSearchResult($str, $query, $numOfWordToAdd) { $lowered = strtolower($query); $str = str_replace($query,$lowered,$str); list($before, $after) = explode($lowered, $str); $before = rtrim($before); $after = ltrim($after); $beforeArray = array_reverse(explode(" ", $before)); $afterArray = explode(" ", $after); $countBeforeArray = count($beforeArray); $countAfterArray = count($afterArray); $beforeString = ""; if($countBeforeArray < $numOfWordToAdd) { $beforeString = implode(' ', $beforeArray); } else { for($i = 0; $i < $numOfWordToAdd; $i++) { $beforeString = $beforeArray[$i] . ' ' . $beforeString; } } $afterString = ""; if($countAfterArray < $numOfWordToAdd) { $afterString = implode(' ', $afterArray); } else { for($i = 0; $i < $numOfWordToAdd; $i++) { $afterString = $afterString . $afterArray[$i] . ' '; } } $string = $beforeString . ' <span class="underline"> ' . $query . ' </span> ' . ' ' . $afterString; return $string; } $body = "<p>This is the body, KeyWoRd to be searched is here.</p>"; $keyword = "keyword"; echo getSearchResult($body,$keyword,1); ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/uOICY
function name:  (null)
number of ops:  9
compiled vars:  !0 = $body, !1 = $keyword
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   42     0  E >   ASSIGN                                                   !0, '%3Cp%3EThis+is+the+body%2C+KeyWoRd+to+be+searched+is+here.%3C%2Fp%3E'
   43     1        ASSIGN                                                   !1, 'keyword'
   44     2        INIT_FCALL                                               'getsearchresult'
          3        SEND_VAR                                                 !0
          4        SEND_VAR                                                 !1
          5        SEND_VAL                                                 1
          6        DO_FCALL                                      0  $4      
          7        ECHO                                                     $4
   45     8      > RETURN                                                   1

Function getsearchresult:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 50, Position 2 = 56
Branch analysis from position: 50
1 jumps found. (Code = 42) Position 1 = 65
Branch analysis from position: 65
2 jumps found. (Code = 43) Position 1 = 68, Position 2 = 74
Branch analysis from position: 68
1 jumps found. (Code = 42) Position 1 = 83
Branch analysis from position: 83
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 74
1 jumps found. (Code = 42) Position 1 = 81
Branch analysis from position: 81
2 jumps found. (Code = 44) Position 1 = 83, Position 2 = 76
Branch analysis from position: 83
Branch analysis from position: 76
2 jumps found. (Code = 44) Position 1 = 83, Position 2 = 76
Branch analysis from position: 83
Branch analysis from position: 76
Branch analysis from position: 56
1 jumps found. (Code = 42) Position 1 = 63
Branch analysis from position: 63
2 jumps found. (Code = 44) Position 1 = 65, Position 2 = 58
Branch analysis from position: 65
Branch analysis from position: 58
2 jumps found. (Code = 44) Position 1 = 65, Position 2 = 58
Branch analysis from position: 65
Branch analysis from position: 58
filename:       /in/uOICY
function name:  getSearchResult
number of ops:  91
compiled vars:  !0 = $str, !1 = $query, !2 = $numOfWordToAdd, !3 = $lowered, !4 = $before, !5 = $after, !6 = $beforeArray, !7 = $afterArray, !8 = $countBeforeArray, !9 = $countAfterArray, !10 = $beforeString, !11 = $i, !12 = $afterString, !13 = $string
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
    3     3        INIT_FCALL                                               'strtolower'
          4        SEND_VAR                                                 !1
          5        DO_ICALL                                         $14     
          6        ASSIGN                                                   !3, $14
    4     7        INIT_FCALL                                               'str_replace'
          8        SEND_VAR                                                 !1
          9        SEND_VAR                                                 !3
         10        SEND_VAR                                                 !0
         11        DO_ICALL                                         $16     
         12        ASSIGN                                                   !0, $16
    5    13        INIT_FCALL                                               'explode'
         14        SEND_VAR                                                 !3
         15        SEND_VAR                                                 !0
         16        DO_ICALL                                         $18     
         17        FETCH_LIST_R                                     $19     $18, 0
         18        ASSIGN                                                   !4, $19
         19        FETCH_LIST_R                                     $21     $18, 1
         20        ASSIGN                                                   !5, $21
         21        FREE                                                     $18
    7    22        INIT_FCALL                                               'rtrim'
         23        SEND_VAR                                                 !4
         24        DO_ICALL                                         $23     
         25        ASSIGN                                                   !4, $23
    8    26        INIT_FCALL                                               'ltrim'
         27        SEND_VAR                                                 !5
         28        DO_ICALL                                         $25     
         29        ASSIGN                                                   !5, $25
   10    30        INIT_FCALL                                               'array_reverse'
         31        INIT_FCALL                                               'explode'
         32        SEND_VAL                                                 '+'
         33        SEND_VAR                                                 !4
         34        DO_ICALL                                         $27     
         35        SEND_VAR                                                 $27
         36        DO_ICALL                                         $28     
         37        ASSIGN                                                   !6, $28
   11    38        INIT_FCALL                                               'explode'
         39        SEND_VAL                                                 '+'
         40        SEND_VAR                                                 !5
         41        DO_ICALL                                         $30     
         42        ASSIGN                                                   !7, $30
   13    43        COUNT                                            ~32     !6
         44        ASSIGN                                                   !8, ~32
   14    45        COUNT                                            ~34     !7
         46        ASSIGN                                                   !9, ~34
   16    47        ASSIGN                                                   !10, ''
   17    48        IS_SMALLER                                               !8, !2
         49      > JMPZ                                                     ~37, ->56
   18    50    >   INIT_FCALL                                               'implode'
         51        SEND_VAL                                                 '+'
         52        SEND_VAR                                                 !6
         53        DO_ICALL                                         $38     
         54        ASSIGN                                                   !10, $38
         55      > JMP                                                      ->65
   21    56    >   ASSIGN                                                   !11, 0
         57      > JMP                                                      ->63
   22    58    >   FETCH_DIM_R                                      ~41     !6, !11
         59        CONCAT                                           ~42     ~41, '+'
         60        CONCAT                                           ~43     ~42, !10
         61        ASSIGN                                                   !10, ~43
   21    62        PRE_INC                                                  !11
         63    >   IS_SMALLER                                               !11, !2
         64      > JMPNZ                                                    ~46, ->58
   26    65    >   ASSIGN                                                   !12, ''
   27    66        IS_SMALLER                                               !9, !2
         67      > JMPZ                                                     ~48, ->74
   28    68    >   INIT_FCALL                                               'implode'
         69        SEND_VAL                                                 '+'
         70        SEND_VAR                                                 !7
         71        DO_ICALL                                         $49     
         72        ASSIGN                                                   !12, $49
         73      > JMP                                                      ->83
   31    74    >   ASSIGN                                                   !11, 0
         75      > JMP                                                      ->81
   32    76    >   FETCH_DIM_R                                      ~52     !7, !11
         77        CONCAT                                           ~53     !12, ~52
         78        CONCAT                                           ~54     ~53, '+'
         79        ASSIGN                                                   !12, ~54
   31    80        PRE_INC                                                  !11
         81    >   IS_SMALLER                                               !11, !2
         82      > JMPNZ                                                    ~57, ->76
   37    83    >   CONCAT                                           ~58     !10, '+%3Cspan+class%3D%22underline%22%3E+'
         84        CONCAT                                           ~59     ~58, !1
         85        CONCAT                                           ~60     ~59, '+%3C%2Fspan%3E+'
         86        CONCAT                                           ~61     ~60, '+'
         87        CONCAT                                           ~62     ~61, !12
         88        ASSIGN                                                   !13, ~62
   39    89      > RETURN                                                   !13
   40    90*     > RETURN                                                   null

End of function getsearchresult

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
161.35 ms | 1407 KiB | 28 Q