3v4l.org

run code in 300+ PHP versions simultaneously
<?php var_dump(firstWordPosition('Will company any do any job, (are there any)?', 'any')); var_dump(firstWordPosition('Will *any* company do *any* job, (are there any)?', 'any')); function firstWordPosition($str, $word) { // There are others, maybe also pass this in or array_merge() for more control. $nonchars = ["'",'"','.',',','!','?','(',')','^','$','#','\n','\r\n','\t',]; // You could also do a strpos() with an if and another argument passed in. // Note that we're padding the $str to with spaces to match begin/end. $pos = stripos(str_replace($nonchars, ' ', " $str "), " $word "); // Have to account for the for-space on " $str ". return $pos ? $pos - 1: false; }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/qh9Rb
function name:  (null)
number of ops:  15
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   INIT_FCALL                                               'var_dump'
          1        INIT_FCALL_BY_NAME                                       'firstWordPosition'
          2        SEND_VAL_EX                                              'Will+company+any+do+any+job%2C+%28are+there+any%29%3F'
          3        SEND_VAL_EX                                              'any'
          4        DO_FCALL                                      0  $0      
          5        SEND_VAR                                                 $0
          6        DO_ICALL                                                 
    4     7        INIT_FCALL                                               'var_dump'
          8        INIT_FCALL_BY_NAME                                       'firstWordPosition'
          9        SEND_VAL_EX                                              'Will+%2Aany%2A+company+do+%2Aany%2A+job%2C+%28are+there+any%29%3F'
         10        SEND_VAL_EX                                              'any'
         11        DO_FCALL                                      0  $2      
         12        SEND_VAR                                                 $2
         13        DO_ICALL                                                 
   15    14      > RETURN                                                   1

Function firstwordposition:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 23
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 24
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 23
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/qh9Rb
function name:  firstWordPosition
number of ops:  26
compiled vars:  !0 = $str, !1 = $word, !2 = $nonchars, !3 = $pos
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    8     2        ASSIGN                                                   !2, <array>
   11     3        INIT_FCALL                                               'stripos'
          4        INIT_FCALL                                               'str_replace'
          5        SEND_VAR                                                 !2
          6        SEND_VAL                                                 '+'
          7        ROPE_INIT                                     3  ~6      '+'
          8        ROPE_ADD                                      1  ~6      ~6, !0
          9        ROPE_END                                      2  ~5      ~6, '+'
         10        SEND_VAL                                                 ~5
         11        DO_ICALL                                         $8      
         12        SEND_VAR                                                 $8
         13        ROPE_INIT                                     3  ~10     '+'
         14        ROPE_ADD                                      1  ~10     ~10, !1
         15        ROPE_END                                      2  ~9      ~10, '+'
         16        SEND_VAL                                                 ~9
         17        DO_ICALL                                         $12     
         18        ASSIGN                                                   !3, $12
   14    19      > JMPZ                                                     !3, ->23
         20    >   SUB                                              ~14     !3, 1
         21        QM_ASSIGN                                        ~15     ~14
         22      > JMP                                                      ->24
         23    >   QM_ASSIGN                                        ~15     <false>
         24    > > RETURN                                                   ~15
   15    25*     > RETURN                                                   null

End of function firstwordposition

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
141.72 ms | 1439 KiB | 16 Q