3v4l.org

run code in 500+ PHP versions simultaneously
<?php $strings = [ '%foo!bar', '@baz', '!bam@bat@bar', '%bee@baa', ]; $field = 'your_column'; $conditionTemplates = [ '&' => '%1$s = ?', '!' => '(%1$s IS NULL OR %1$s != ?)', '%' => '%1$s LIKE ?', '@' => '%1$s NOT LIKE ?', ]; $needsTrailingWildcard = ['%', '@']; foreach ($strings as $string) { $conditions = []; // reset for demo $params = []; // reset for demo preg_match_all('~([&%@!])([^&%@!]+)~', $string, $matches, PREG_SET_ORDER); foreach ($matches as $match) { $conditions[] = sprintf($conditionTemplates[$match[1]], $field); $params[] = $match[2] . (in_array($match[1], $needsTrailingWildcard) ? '%' : ''); } var_export([implode(' AND ', $conditions), $params]); echo "\n"; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 5, Position 2 = 44
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 44
Branch analysis from position: 6
2 jumps found. (Code = 77) Position 1 = 15, Position 2 = 35
Branch analysis from position: 15
2 jumps found. (Code = 78) Position 1 = 16, Position 2 = 35
Branch analysis from position: 16
2 jumps found. (Code = 43) Position 1 = 28, Position 2 = 30
Branch analysis from position: 28
1 jumps found. (Code = 42) Position 1 = 31
Branch analysis from position: 31
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
Branch analysis from position: 30
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
Branch analysis from position: 35
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 35
Branch analysis from position: 44
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 44
filename:       /in/X3JYP
function name:  (null)
number of ops:  46
compiled vars:  !0 = $strings, !1 = $field, !2 = $conditionTemplates, !3 = $needsTrailingWildcard, !4 = $string, !5 = $conditions, !6 = $params, !7 = $matches, !8 = $match
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, <array>
    9     1        ASSIGN                                                       !1, 'your_column'
   10     2        ASSIGN                                                       !2, <array>
   16     3        ASSIGN                                                       !3, <array>
   18     4      > FE_RESET_R                                           $13     !0, ->44
          5    > > FE_FETCH_R                                                   $13, !4, ->44
   19     6    >   ASSIGN                                                       !5, <array>
   20     7        ASSIGN                                                       !6, <array>
   21     8        INIT_FCALL                                                   'preg_match_all'
          9        SEND_VAL                                                     '%7E%28%5B%26%25%40%21%5D%29%28%5B%5E%26%25%40%21%5D%2B%29%7E'
         10        SEND_VAR                                                     !4
         11        SEND_REF                                                     !7
         12        SEND_VAL                                                     2
         13        DO_ICALL                                                     
   22    14      > FE_RESET_R                                           $17     !7, ->35
         15    > > FE_FETCH_R                                                   $17, !8, ->35
   23    16    >   INIT_FCALL                                                   'sprintf'
         17        FETCH_DIM_R                                          ~19     !8, 1
         18        FETCH_DIM_R                                          ~20     !2, ~19
         19        SEND_VAL                                                     ~20
         20        SEND_VAR                                                     !1
         21        DO_ICALL                                             $21     
         22        ASSIGN_DIM                                                   !5
         23        OP_DATA                                                      $21
   24    24        FETCH_DIM_R                                          ~23     !8, 2
         25        FETCH_DIM_R                                          ~24     !8, 1
         26        FRAMELESS_ICALL_2                in_array            ~25     ~24, !3
         27      > JMPZ                                                         ~25, ->30
         28    >   QM_ASSIGN                                            ~26     '%25'
         29      > JMP                                                          ->31
         30    >   QM_ASSIGN                                            ~26     ''
         31    >   CONCAT                                               ~27     ~23, ~26
         32        ASSIGN_DIM                                                   !6
         33        OP_DATA                                                      ~27
   22    34      > JMP                                                          ->15
         35    >   FE_FREE                                                      $17
   26    36        INIT_FCALL                                                   'var_export'
         37        FRAMELESS_ICALL_2                implode             ~28     '+AND+', !5
         38        INIT_ARRAY                                           ~29     ~28
         39        ADD_ARRAY_ELEMENT                                    ~29     !6
         40        SEND_VAL                                                     ~29
         41        DO_ICALL                                                     
   27    42        ECHO                                                         '%0A'
   18    43      > JMP                                                          ->5
         44    >   FE_FREE                                                      $13
   28    45      > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
159.41 ms | 2113 KiB | 16 Q