3v4l.org

run code in 300+ 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 = 50
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 50
Branch analysis from position: 6
2 jumps found. (Code = 77) Position 1 = 15, Position 2 = 38
Branch analysis from position: 15
2 jumps found. (Code = 78) Position 1 = 16, Position 2 = 38
Branch analysis from position: 16
2 jumps found. (Code = 43) Position 1 = 31, Position 2 = 33
Branch analysis from position: 31
1 jumps found. (Code = 42) Position 1 = 34
Branch analysis from position: 34
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
Branch analysis from position: 33
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
Branch analysis from position: 38
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 38
Branch analysis from position: 50
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 50
filename:       /in/X3JYP
function name:  (null)
number of ops:  52
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, ->50
          5    > > FE_FETCH_R                                               $13, !4, ->50
   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, ->38
         15    > > FE_FETCH_R                                               $17, !8, ->38
   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        INIT_FCALL                                               'in_array'
         26        FETCH_DIM_R                                      ~24     !8, 1
         27        SEND_VAL                                                 ~24
         28        SEND_VAR                                                 !3
         29        DO_ICALL                                         $25     
         30      > JMPZ                                                     $25, ->33
         31    >   QM_ASSIGN                                        ~26     '%25'
         32      > JMP                                                      ->34
         33    >   QM_ASSIGN                                        ~26     ''
         34    >   CONCAT                                           ~27     ~23, ~26
         35        ASSIGN_DIM                                               !6
         36        OP_DATA                                                  ~27
   22    37      > JMP                                                      ->15
         38    >   FE_FREE                                                  $17
   26    39        INIT_FCALL                                               'var_export'
         40        INIT_FCALL                                               'implode'
         41        SEND_VAL                                                 '+AND+'
         42        SEND_VAR                                                 !5
         43        DO_ICALL                                         $28     
         44        INIT_ARRAY                                       ~29     $28
         45        ADD_ARRAY_ELEMENT                                ~29     !6
         46        SEND_VAL                                                 ~29
         47        DO_ICALL                                                 
   27    48        ECHO                                                     '%0A'
   18    49      > JMP                                                      ->5
         50    >   FE_FREE                                                  $13
   28    51      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
176.28 ms | 1392 KiB | 23 Q