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));
Output for 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
Warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in /in/ae99i on line 9 Warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in /in/ae99i on line 9 Warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in /in/ae99i on line 9 Warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in /in/ae99i on line 9 Warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in /in/ae99i on line 9 Array ( [] => Array ( [0] => text/html; charset=UTF-8 [1] => Funky/1.0 [2] => foo=bar [3] => baz=quux [4] => works too ) )
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 Warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in /in/ae99i on line 9 Warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in /in/ae99i on line 9 Warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in /in/ae99i on line 9 Warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in /in/ae99i on line 9 Warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in /in/ae99i on line 9 Array ( [] => Array ( [0] => text/html; charset=UTF-8 [1] => Funky/1.0 [2] => foo=bar [3] => baz=quux [4] => works too ) )
Output for 5.5.0 - 5.5.38, 5.6.0 - 5.6.40
Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /in/ae99i on line 9 Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /in/ae99i on line 9 Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /in/ae99i on line 9 Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /in/ae99i on line 9 Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /in/ae99i on line 9 Array ( [Content-Type] => text/html; charset=UTF-8 [Server] => Funky/1.0 [Set-Cookie] => Array ( [0] => foo=bar [1] => baz=quux ) [Folded] => works too )

preferences:
268.72 ms | 403 KiB | 330 Q