3v4l.org

run code in 300+ PHP versions simultaneously
<?php function getAllWholeWordPos($s,$word){ $b = " "; $delimited = "$b$word$b"; $retval = false; for ($i=0, $max = strlen( $s ); $i < $max; $i++) { if ( !ctype_alpha( $s[$i] ) ){ $s[$i] = $b; } } while ( ( $pos = stripos( $s, $delimited) ) !== false ) { $retval[] = $pos + 1; for ( $i=0, $max = $pos + 1 + strlen( $word ); $i <= $max; $i++) { $s[$i] = $b; } } return $retval; } $whole_word = "any"; $str = "Will *$whole_word* company do *$whole_word* job, (are there $whole_word)?"; echo "\nString: \"$str\""; $result = getAllWholeWordPos( $str, $whole_word ); $times = count( $result ); echo "\n\nThe word \"$whole_word\" occurs $times times:\n"; foreach ($result as $pos) { echo "\nPosition: ",$pos; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 27, Position 2 = 31
Branch analysis from position: 27
2 jumps found. (Code = 78) Position 1 = 28, Position 2 = 31
Branch analysis from position: 28
1 jumps found. (Code = 42) Position 1 = 27
Branch analysis from position: 27
Branch analysis from position: 31
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 31
filename:       /in/ZEoZe
function name:  (null)
number of ops:  33
compiled vars:  !0 = $whole_word, !1 = $str, !2 = $result, !3 = $times, !4 = $pos
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   ASSIGN                                                   !0, 'any'
   24     1        ROPE_INIT                                     7  ~7      'Will+%2A'
          2        ROPE_ADD                                      1  ~7      ~7, !0
          3        ROPE_ADD                                      2  ~7      ~7, '%2A+company+do+%2A'
          4        ROPE_ADD                                      3  ~7      ~7, !0
          5        ROPE_ADD                                      4  ~7      ~7, '%2A+job%2C+%28are+there+'
          6        ROPE_ADD                                      5  ~7      ~7, !0
          7        ROPE_END                                      6  ~6      ~7, '%29%3F'
          8        ASSIGN                                                   !1, ~6
   26     9        ROPE_INIT                                     3  ~13     '%0AString%3A+%22'
         10        ROPE_ADD                                      1  ~13     ~13, !1
         11        ROPE_END                                      2  ~12     ~13, '%22'
         12        ECHO                                                     ~12
   28    13        INIT_FCALL                                               'getallwholewordpos'
         14        SEND_VAR                                                 !1
         15        SEND_VAR                                                 !0
         16        DO_FCALL                                      0  $15     
         17        ASSIGN                                                   !2, $15
   29    18        COUNT                                            ~17     !2
         19        ASSIGN                                                   !3, ~17
   30    20        ROPE_INIT                                     5  ~20     '%0A%0AThe+word+%22'
         21        ROPE_ADD                                      1  ~20     ~20, !0
         22        ROPE_ADD                                      2  ~20     ~20, '%22+occurs+'
         23        ROPE_ADD                                      3  ~20     ~20, !3
         24        ROPE_END                                      4  ~19     ~20, '+times%3A%0A'
         25        ECHO                                                     ~19
   31    26      > FE_RESET_R                                       $23     !2, ->31
         27    > > FE_FETCH_R                                               $23, !4, ->31
   32    28    >   ECHO                                                     '%0APosition%3A+'
         29        ECHO                                                     !4
   31    30      > JMP                                                      ->27
         31    >   FE_FREE                                                  $23
   33    32      > RETURN                                                   1

Function getallwholewordpos:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
2 jumps found. (Code = 44) Position 1 = 23, Position 2 = 12
Branch analysis from position: 23
1 jumps found. (Code = 42) Position 1 = 38
Branch analysis from position: 38
2 jumps found. (Code = 44) Position 1 = 45, Position 2 = 24
Branch analysis from position: 45
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 36
Branch analysis from position: 36
2 jumps found. (Code = 44) Position 1 = 38, Position 2 = 33
Branch analysis from position: 38
Branch analysis from position: 33
2 jumps found. (Code = 44) Position 1 = 38, Position 2 = 33
Branch analysis from position: 38
Branch analysis from position: 33
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 20
Branch analysis from position: 18
2 jumps found. (Code = 44) Position 1 = 23, Position 2 = 12
Branch analysis from position: 23
Branch analysis from position: 12
Branch analysis from position: 20
filename:       /in/ZEoZe
function name:  getAllWholeWordPos
number of ops:  47
compiled vars:  !0 = $s, !1 = $word, !2 = $b, !3 = $delimited, !4 = $retval, !5 = $i, !6 = $max, !7 = $pos
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    4     2        ASSIGN                                                   !2, '+'
    5     3        ROPE_INIT                                     3  ~10     !2
          4        ROPE_ADD                                      1  ~10     ~10, !1
          5        ROPE_END                                      2  ~9      ~10, !2
          6        ASSIGN                                                   !3, ~9
    6     7        ASSIGN                                                   !4, <false>
    8     8        ASSIGN                                                   !5, 0
          9        STRLEN                                           ~15     !0
         10        ASSIGN                                                   !6, ~15
         11      > JMP                                                      ->21
    9    12    >   INIT_FCALL                                               'ctype_alpha'
         13        FETCH_DIM_R                                      ~17     !0, !5
         14        SEND_VAL                                                 ~17
         15        DO_ICALL                                         $18     
         16        BOOL_NOT                                         ~19     $18
         17      > JMPZ                                                     ~19, ->20
   10    18    >   ASSIGN_DIM                                               !0, !5
         19        OP_DATA                                                  !2
    8    20    >   PRE_INC                                                  !5
         21    >   IS_SMALLER                                               !5, !6
         22      > JMPNZ                                                    ~22, ->12
   14    23    > > JMP                                                      ->38
   15    24    >   ADD                                              ~24     !7, 1
         25        ASSIGN_DIM                                               !4
         26        OP_DATA                                                  ~24
   16    27        ASSIGN                                                   !5, 0
         28        ADD                                              ~26     !7, 1
         29        STRLEN                                           ~27     !1
         30        ADD                                              ~28     ~26, ~27
         31        ASSIGN                                                   !6, ~28
         32      > JMP                                                      ->36
   17    33    >   ASSIGN_DIM                                               !0, !5
         34        OP_DATA                                                  !2
   16    35        PRE_INC                                                  !5
         36    >   IS_SMALLER_OR_EQUAL                                      !5, !6
         37      > JMPNZ                                                    ~32, ->33
   14    38    >   INIT_FCALL                                               'stripos'
         39        SEND_VAR                                                 !0
         40        SEND_VAR                                                 !3
         41        DO_ICALL                                         $33     
         42        ASSIGN                                           ~34     !7, $33
         43        TYPE_CHECK                                  1018          ~34
         44      > JMPNZ                                                    ~35, ->24
   20    45    > > RETURN                                                   !4
   21    46*     > RETURN                                                   null

End of function getallwholewordpos

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
141.99 ms | 1445 KiB | 16 Q