3v4l.org

run code in 300+ PHP versions simultaneously
<?php function parseHeaders( $header ) { $retVal = array(); $fields = explode("\r\n", preg_replace('/\x0D\x0A[\x09\x20]+/', ' ', $header)); foreach( $fields as $field ) { if( preg_match('/([^:]+): (.+)/m', $field, $match) ) { $match[1] = preg_replace('/(?<=^|[\x09\x20\x2D])./e', 'strtoupper("\0")', strtolower(trim($match[1]))); if( isset($retVal[$match[1]]) ) { if (!is_array($retVal[$match[1]])) { $retVal[$match[1]] = array($retVal[$match[1]]); } $retVal[$match[1]][] = $match[2]; } else { $retVal[$match[1]] = trim($match[2]); } } } return $retVal; } $headers = "HTTP/1.1 200 OK\r\n". "content-type: text/html; charset=UTF-8\r\n". "Server: Funky/1.0\r\n". "Set-Cookie: foo=bar\r\n". "Set-Cookie: baz=quux\r\n". "Folded: works\r\n\ttoo\r\n"; print_r(parseHeaders($headers));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ae99i
function name:  (null)
number of ops:  8
compiled vars:  !0 = $headers
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   ASSIGN                                                   !0, 'HTTP%2F1.1+200+OK%0D%0Acontent-type%3A+text%2Fhtml%3B+charset%3DUTF-8%0D%0AServer%3A+Funky%2F1.0%0D%0ASet-Cookie%3A+foo%3Dbar%0D%0ASet-Cookie%3A+baz%3Dquux%0D%0AFolded%3A+works%0D%0A%09too%0D%0A'
   30     1        INIT_FCALL                                               'print_r'
          2        INIT_FCALL                                               'parseheaders'
          3        SEND_VAR                                                 !0
          4        DO_FCALL                                      0  $2      
          5        SEND_VAR                                                 $2
          6        DO_ICALL                                                 
          7      > RETURN                                                   1

Function parseheaders:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 13, Position 2 = 62
Branch analysis from position: 13
2 jumps found. (Code = 78) Position 1 = 14, Position 2 = 62
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 61
Branch analysis from position: 20
2 jumps found. (Code = 43) Position 1 = 37, Position 2 = 54
Branch analysis from position: 37
2 jumps found. (Code = 43) Position 1 = 42, Position 2 = 48
Branch analysis from position: 42
1 jumps found. (Code = 42) Position 1 = 61
Branch analysis from position: 61
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
Branch analysis from position: 48
Branch analysis from position: 54
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
Branch analysis from position: 61
Branch analysis from position: 62
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 62
filename:       /in/ae99i
function name:  parseHeaders
number of ops:  65
compiled vars:  !0 = $header, !1 = $retVal, !2 = $fields, !3 = $field, !4 = $match
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    5     1        ASSIGN                                                   !1, <array>
    6     2        INIT_FCALL                                               'explode'
          3        SEND_VAL                                                 '%0D%0A'
          4        INIT_FCALL                                               'preg_replace'
          5        SEND_VAL                                                 '%2F%5Cx0D%5Cx0A%5B%5Cx09%5Cx20%5D%2B%2F'
          6        SEND_VAL                                                 '+'
          7        SEND_VAR                                                 !0
          8        DO_ICALL                                         $6      
          9        SEND_VAR                                                 $6
         10        DO_ICALL                                         $7      
         11        ASSIGN                                                   !2, $7
    7    12      > FE_RESET_R                                       $9      !2, ->62
         13    > > FE_FETCH_R                                               $9, !3, ->62
    8    14    >   INIT_FCALL                                               'preg_match'
         15        SEND_VAL                                                 '%2F%28%5B%5E%3A%5D%2B%29%3A+%28.%2B%29%2Fm'
         16        SEND_VAR                                                 !3
         17        SEND_REF                                                 !4
         18        DO_ICALL                                         $10     
         19      > JMPZ                                                     $10, ->61
    9    20    >   INIT_FCALL                                               'preg_replace'
         21        SEND_VAL                                                 '%2F%28%3F%3C%3D%5E%7C%5B%5Cx09%5Cx20%5Cx2D%5D%29.%2Fe'
         22        SEND_VAL                                                 'strtoupper%28%22%5C0%22%29'
         23        INIT_FCALL                                               'strtolower'
         24        INIT_FCALL                                               'trim'
         25        FETCH_DIM_R                                      ~12     !4, 1
         26        SEND_VAL                                                 ~12
         27        DO_ICALL                                         $13     
         28        SEND_VAR                                                 $13
         29        DO_ICALL                                         $14     
         30        SEND_VAR                                                 $14
         31        DO_ICALL                                         $15     
         32        ASSIGN_DIM                                               !4, 1
         33        OP_DATA                                                  $15
   10    34        FETCH_DIM_R                                      ~16     !4, 1
         35        ISSET_ISEMPTY_DIM_OBJ                         0          !1, ~16
         36      > JMPZ                                                     ~17, ->54
   11    37    >   FETCH_DIM_R                                      ~18     !4, 1
         38        FETCH_DIM_R                                      ~19     !1, ~18
         39        TYPE_CHECK                                  128  ~20     ~19
         40        BOOL_NOT                                         ~21     ~20
         41      > JMPZ                                                     ~21, ->48
   12    42    >   FETCH_DIM_R                                      ~22     !4, 1
         43        FETCH_DIM_R                                      ~24     !4, 1
         44        FETCH_DIM_R                                      ~25     !1, ~24
         45        INIT_ARRAY                                       ~26     ~25
         46        ASSIGN_DIM                                               !1, ~22
         47        OP_DATA                                                  ~26
   14    48    >   FETCH_DIM_R                                      ~27     !4, 1
         49        FETCH_DIM_R                                      ~30     !4, 2
         50        FETCH_DIM_W                                      $28     !1, ~27
         51        ASSIGN_DIM                                               $28
         52        OP_DATA                                                  ~30
         53      > JMP                                                      ->61
   16    54    >   FETCH_DIM_R                                      ~31     !4, 1
         55        INIT_FCALL                                               'trim'
         56        FETCH_DIM_R                                      ~33     !4, 2
         57        SEND_VAL                                                 ~33
         58        DO_ICALL                                         $34     
         59        ASSIGN_DIM                                               !1, ~31
         60        OP_DATA                                                  $34
    7    61    > > JMP                                                      ->13
         62    >   FE_FREE                                                  $9
   20    63      > RETURN                                                   !1
   21    64*     > RETURN                                                   null

End of function parseheaders

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
174.24 ms | 1403 KiB | 26 Q