3v4l.org

run code in 300+ PHP versions simultaneously
<?PHP $list = [ // an array list of string/regex that i want to check "lorem ipsum", // a words "example", // another word "/(nulla)/", // a regex "/[,.]/", // illustrate regex offset ]; $input_string = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer quam ex, vestibulum sed laoreet auctor, iaculis eget velit. Donec mattis, nulla ac suscipit maximus, leo metus vestibulum eros, nec finibus nisl dui ut est. Nam tristique varius mauris, a faucibus augue."; // get matches and offset $match_count = 0; $matches = []; foreach($list as $v) { // make pattern from strings not enclosed in delimiters $pattern = $v[0] == '/' ? $v : "/".preg_quote($v, "/")."/i"; // using preg_match_all to get each match and offset if(preg_match_all($pattern, $input_string, $out, PREG_OFFSET_CAPTURE)) { foreach($out[0] AS $m) { echo $m[0]." matched at offset ".$m[1]."!\n"; } } }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 5, Position 2 = 38
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 38
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 11
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
2 jumps found. (Code = 43) Position 1 = 26, Position 2 = 37
Branch analysis from position: 26
2 jumps found. (Code = 77) Position 1 = 28, Position 2 = 36
Branch analysis from position: 28
2 jumps found. (Code = 78) Position 1 = 29, Position 2 = 36
Branch analysis from position: 29
1 jumps found. (Code = 42) Position 1 = 28
Branch analysis from position: 28
Branch analysis from position: 36
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 36
Branch analysis from position: 37
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 26, Position 2 = 37
Branch analysis from position: 26
Branch analysis from position: 37
Branch analysis from position: 38
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 38
filename:       /in/Klnog
function name:  (null)
number of ops:  40
compiled vars:  !0 = $list, !1 = $input_string, !2 = $match_count, !3 = $matches, !4 = $v, !5 = $pattern, !6 = $out, !7 = $m
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   10     1        ASSIGN                                                   !1, 'Lorem+ipsum+dolor+sit+amet%2C+consectetur+adipiscing+elit.+Integer+quam+ex%2C+vestibulum+sed+laoreet+auctor%2C+iaculis+eget+velit.+Donec+mattis%2C+nulla+ac+suscipit+maximus%2C+leo++metus+vestibulum+eros%2C+nec+finibus+nisl+dui+ut+est.+Nam+tristique+varius+mauris%2C+a+faucibus+augue.'
   13     2        ASSIGN                                                   !2, 0
          3        ASSIGN                                                   !3, <array>
   15     4      > FE_RESET_R                                       $12     !0, ->38
          5    > > FE_FETCH_R                                               $12, !4, ->38
   18     6    >   FETCH_DIM_R                                      ~13     !4, 0
          7        IS_EQUAL                                                 ~13, '%2F'
          8      > JMPZ                                                     ~14, ->11
          9    >   QM_ASSIGN                                        ~15     !4
         10      > JMP                                                      ->18
         11    >   INIT_FCALL                                               'preg_quote'
         12        SEND_VAR                                                 !4
         13        SEND_VAL                                                 '%2F'
         14        DO_ICALL                                         $16     
         15        CONCAT                                           ~17     '%2F', $16
         16        CONCAT                                           ~18     ~17, '%2Fi'
         17        QM_ASSIGN                                        ~15     ~18
         18    >   ASSIGN                                                   !5, ~15
   21    19        INIT_FCALL                                               'preg_match_all'
         20        SEND_VAR                                                 !5
         21        SEND_VAR                                                 !1
         22        SEND_REF                                                 !6
         23        SEND_VAL                                                 256
         24        DO_ICALL                                         $20     
         25      > JMPZ                                                     $20, ->37
   23    26    >   FETCH_DIM_R                                      ~21     !6, 0
         27      > FE_RESET_R                                       $22     ~21, ->36
         28    > > FE_FETCH_R                                               $22, !7, ->36
   24    29    >   FETCH_DIM_R                                      ~23     !7, 0
         30        CONCAT                                           ~24     ~23, '+matched+at+offset+'
         31        FETCH_DIM_R                                      ~25     !7, 1
         32        CONCAT                                           ~26     ~24, ~25
         33        CONCAT                                           ~27     ~26, '%21%0A'
         34        ECHO                                                     ~27
   23    35      > JMP                                                      ->28
         36    >   FE_FREE                                                  $22
   15    37    > > JMP                                                      ->5
         38    >   FE_FREE                                                  $12
   27    39      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
141.76 ms | 1008 KiB | 15 Q