3v4l.org

run code in 300+ PHP versions simultaneously
<?php function parse_search($string,$quote='"') { $terms = array(); $accept = array('"','\''); if( !is_string($string) || !is_string($quote) || strlen($quote) > 1 || !in_array($quote,$accept) ) { return false; } // matches all manner of whitespace $whitespace = '/\s+/'; // what to change escaped quotes to, i.e. \' or \" $escq = '%escq%'; // ways that spaces may be encoded $encoded = array('+'); // we'll be using it a lot $space = ' '; // turn URL encoded spaces into normal ones $str = str_replace($encoded,$space,stripslashes(html_entity_decode(urldecode($string)))); // replace multiple/odd whitespace characters with single spaces $str = trim(preg_replace($whitespace,$space,$str)); // allow the user to escape quotes with backslash $str = str_replace('\\'.$quote,$escq,$str); // get the number of quotes $count = substr_count($str,$quote); // if no matching quotes, just split it if($count < 2) { return explode($space,$str); } // as long as there is a matching pair of quotes while($count > 1) { $before = strpos($str,$quote); $start = $before + 1; $end = strpos($str,$quote,$start); $after = $end + 1; $length = $end - $start; // everything before the quote $beforeStr = rtrim(substr($str,0,$before)); // break it apart, add to the terms list $terms = array_merge($terms,explode($space,$beforeStr)); // add the quote as a phrase $terms[] = trim(substr($str,$start,$length)); // trim off everything up to and including the closing quote $str = trim(substr($str,$after)); $count = substr_count($str,$quote); } // no matching quotes left, just split and add what's left $terms = array_merge($terms,explode($space,$str)); // unescape the escaped quotes foreach($terms as &$term) { $term = str_replace($escq,$quote,$term); } // remove empty entries return array_filter($terms); } $parsed = parse_search('"Cityscape"');
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/HnfOP
function name:  (null)
number of ops:  5
compiled vars:  !0 = $parsed
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   73     0  E >   INIT_FCALL                                               'parse_search'
          1        SEND_VAL                                                 '%22Cityscape%22'
          2        DO_FCALL                                      0  $1      
          3        ASSIGN                                                   !0, $1
          4      > RETURN                                                   1

Function parse_search:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 7, Position 2 = 10
Branch analysis from position: 7
2 jumps found. (Code = 47) Position 1 = 11, Position 2 = 14
Branch analysis from position: 11
2 jumps found. (Code = 47) Position 1 = 15, Position 2 = 21
Branch analysis from position: 15
2 jumps found. (Code = 43) Position 1 = 22, Position 2 = 23
Branch analysis from position: 22
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 23
2 jumps found. (Code = 43) Position 1 = 65, Position 2 = 70
Branch analysis from position: 65
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 70
1 jumps found. (Code = 42) Position 1 = 129
Branch analysis from position: 129
2 jumps found. (Code = 44) Position 1 = 131, Position 2 = 71
Branch analysis from position: 131
2 jumps found. (Code = 125) Position 1 = 141, Position 2 = 149
Branch analysis from position: 141
2 jumps found. (Code = 126) Position 1 = 142, Position 2 = 149
Branch analysis from position: 142
1 jumps found. (Code = 42) Position 1 = 141
Branch analysis from position: 141
Branch analysis from position: 149
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 149
Branch analysis from position: 71
2 jumps found. (Code = 44) Position 1 = 131, Position 2 = 71
Branch analysis from position: 131
Branch analysis from position: 71
Branch analysis from position: 21
Branch analysis from position: 14
Branch analysis from position: 10
filename:       /in/HnfOP
function name:  parse_search
number of ops:  155
compiled vars:  !0 = $string, !1 = $quote, !2 = $terms, !3 = $accept, !4 = $whitespace, !5 = $escq, !6 = $encoded, !7 = $space, !8 = $str, !9 = $count, !10 = $before, !11 = $start, !12 = $end, !13 = $after, !14 = $length, !15 = $beforeStr, !16 = $term
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      '%22'
    3     2        ASSIGN                                                   !2, <array>
    4     3        ASSIGN                                                   !3, <array>
    7     4        TYPE_CHECK                                   64  ~19     !0
          5        BOOL_NOT                                         ~20     ~19
          6      > JMPNZ_EX                                         ~20     ~20, ->10
    8     7    >   TYPE_CHECK                                   64  ~21     !1
          8        BOOL_NOT                                         ~22     ~21
          9        BOOL                                             ~20     ~22
         10    > > JMPNZ_EX                                         ~20     ~20, ->14
    9    11    >   STRLEN                                           ~23     !1
         12        IS_SMALLER                                       ~24     1, ~23
         13        BOOL                                             ~20     ~24
         14    > > JMPNZ_EX                                         ~20     ~20, ->21
   10    15    >   INIT_FCALL                                               'in_array'
         16        SEND_VAR                                                 !1
         17        SEND_VAR                                                 !3
         18        DO_ICALL                                         $25     
         19        BOOL_NOT                                         ~26     $25
         20        BOOL                                             ~20     ~26
         21    > > JMPZ                                                     ~20, ->23
   12    22    > > RETURN                                                   <false>
   15    23    >   ASSIGN                                                   !4, '%2F%5Cs%2B%2F'
   17    24        ASSIGN                                                   !5, '%25escq%25'
   19    25        ASSIGN                                                   !6, <array>
   21    26        ASSIGN                                                   !7, '+'
   24    27        INIT_FCALL                                               'str_replace'
         28        SEND_VAR                                                 !6
         29        SEND_VAR                                                 !7
         30        INIT_FCALL                                               'stripslashes'
         31        INIT_FCALL                                               'html_entity_decode'
         32        INIT_FCALL                                               'urldecode'
         33        SEND_VAR                                                 !0
         34        DO_ICALL                                         $31     
         35        SEND_VAR                                                 $31
         36        DO_ICALL                                         $32     
         37        SEND_VAR                                                 $32
         38        DO_ICALL                                         $33     
         39        SEND_VAR                                                 $33
         40        DO_ICALL                                         $34     
         41        ASSIGN                                                   !8, $34
   27    42        INIT_FCALL                                               'trim'
         43        INIT_FCALL                                               'preg_replace'
         44        SEND_VAR                                                 !4
         45        SEND_VAR                                                 !7
         46        SEND_VAR                                                 !8
         47        DO_ICALL                                         $36     
         48        SEND_VAR                                                 $36
         49        DO_ICALL                                         $37     
         50        ASSIGN                                                   !8, $37
   30    51        INIT_FCALL                                               'str_replace'
         52        CONCAT                                           ~39     '%5C', !1
         53        SEND_VAL                                                 ~39
         54        SEND_VAR                                                 !5
         55        SEND_VAR                                                 !8
         56        DO_ICALL                                         $40     
         57        ASSIGN                                                   !8, $40
   33    58        INIT_FCALL                                               'substr_count'
         59        SEND_VAR                                                 !8
         60        SEND_VAR                                                 !1
         61        DO_ICALL                                         $42     
         62        ASSIGN                                                   !9, $42
   36    63        IS_SMALLER                                               !9, 2
         64      > JMPZ                                                     ~44, ->70
   37    65    >   INIT_FCALL                                               'explode'
         66        SEND_VAR                                                 !7
         67        SEND_VAR                                                 !8
         68        DO_ICALL                                         $45     
         69      > RETURN                                                   $45
   40    70    > > JMP                                                      ->129
   41    71    >   INIT_FCALL                                               'strpos'
         72        SEND_VAR                                                 !8
         73        SEND_VAR                                                 !1
         74        DO_ICALL                                         $46     
         75        ASSIGN                                                   !10, $46
   42    76        ADD                                              ~48     !10, 1
         77        ASSIGN                                                   !11, ~48
   43    78        INIT_FCALL                                               'strpos'
         79        SEND_VAR                                                 !8
         80        SEND_VAR                                                 !1
         81        SEND_VAR                                                 !11
         82        DO_ICALL                                         $50     
         83        ASSIGN                                                   !12, $50
   44    84        ADD                                              ~52     !12, 1
         85        ASSIGN                                                   !13, ~52
   45    86        SUB                                              ~54     !12, !11
         87        ASSIGN                                                   !14, ~54
   48    88        INIT_FCALL                                               'rtrim'
         89        INIT_FCALL                                               'substr'
         90        SEND_VAR                                                 !8
         91        SEND_VAL                                                 0
         92        SEND_VAR                                                 !10
         93        DO_ICALL                                         $56     
         94        SEND_VAR                                                 $56
         95        DO_ICALL                                         $57     
         96        ASSIGN                                                   !15, $57
   51    97        INIT_FCALL                                               'array_merge'
         98        SEND_VAR                                                 !2
         99        INIT_FCALL                                               'explode'
        100        SEND_VAR                                                 !7
        101        SEND_VAR                                                 !15
        102        DO_ICALL                                         $59     
        103        SEND_VAR                                                 $59
        104        DO_ICALL                                         $60     
        105        ASSIGN                                                   !2, $60
   54   106        INIT_FCALL                                               'trim'
        107        INIT_FCALL                                               'substr'
        108        SEND_VAR                                                 !8
        109        SEND_VAR                                                 !11
        110        SEND_VAR                                                 !14
        111        DO_ICALL                                         $63     
        112        SEND_VAR                                                 $63
        113        DO_ICALL                                         $64     
        114        ASSIGN_DIM                                               !2
        115        OP_DATA                                                  $64
   57   116        INIT_FCALL                                               'trim'
        117        INIT_FCALL                                               'substr'
        118        SEND_VAR                                                 !8
        119        SEND_VAR                                                 !13
        120        DO_ICALL                                         $65     
        121        SEND_VAR                                                 $65
        122        DO_ICALL                                         $66     
        123        ASSIGN                                                   !8, $66
   59   124        INIT_FCALL                                               'substr_count'
        125        SEND_VAR                                                 !8
        126        SEND_VAR                                                 !1
        127        DO_ICALL                                         $68     
        128        ASSIGN                                                   !9, $68
   40   129    >   IS_SMALLER                                               1, !9
        130      > JMPNZ                                                    ~70, ->71
   63   131    >   INIT_FCALL                                               'array_merge'
        132        SEND_VAR                                                 !2
        133        INIT_FCALL                                               'explode'
        134        SEND_VAR                                                 !7
        135        SEND_VAR                                                 !8
        136        DO_ICALL                                         $71     
        137        SEND_VAR                                                 $71
        138        DO_ICALL                                         $72     
        139        ASSIGN                                                   !2, $72
   66   140      > FE_RESET_RW                                      $74     !2, ->149
        141    > > FE_FETCH_RW                                              $74, !16, ->149
   67   142    >   INIT_FCALL                                               'str_replace'
        143        SEND_VAR                                                 !5
        144        SEND_VAR                                                 !1
        145        SEND_VAR                                                 !16
        146        DO_ICALL                                         $75     
        147        ASSIGN                                                   !16, $75
   66   148      > JMP                                                      ->141
        149    >   FE_FREE                                                  $74
   70   150        INIT_FCALL                                               'array_filter'
        151        SEND_VAR                                                 !2
        152        DO_ICALL                                         $77     
        153      > RETURN                                                   $77
   71   154*     > RETURN                                                   null

End of function parse_search

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
185.56 ms | 1411 KiB | 42 Q