3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php namespace NotGlobal; const PHP_URL_SCHEME = 0x001; const PHP_URL_USER = 0x002; const PHP_URL_PASS = 0x004; const PHP_URL_HOST = 0x008; const PHP_URL_PORT = 0x010; const PHP_URL_PATH = 0x020; const PHP_URL_QUERY = 0x040; const PHP_URL_FRAGMENT = 0x080; const PHP_URL_ALL = 0x0FF; const PHP_URL_REQUIRE_SCHEME = 0x100; const PHP_URL_DISALLOW_EMPTY_AUTHORITY = 0x200; function parse_url($url, $flags = PHP_URL_ALL) { static $map = [ 'scheme' => 1, 'user' => 2, 'pass' => 3, 'host' => 4, 'port' => 5, 'path' => 6, 'query' => 7, 'fragment' => 8, ]; static $pattern = '!^([a-zA-Z][a-zA-Z0-9+.\-]*):(?://(?:([^:@/\s]+)(?::([^:@/\s]+))?@)?([^:/?#\s]*)(?::([0-9]+))?(?=[/?#]|$))?([^?#\s]+)?(?:\?([^#\s]+))?(?:#(\S+))?$!'; if (!preg_match($pattern, trim($url), $matches)) { return false; } $result = []; foreach ($map as $component => $index) { if ($matches[$index] !== '') { $result[$component] = $index === 5 ? (int) $matches[$index] : $matches[$index]; } } return $result; } var_dump(parse_url('scheme://host:12345/path?query#fragment'));
Output for 5.4.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
array(6) { ["scheme"]=> string(6) "scheme" ["host"]=> string(4) "host" ["port"]=> int(12345) ["path"]=> string(5) "/path" ["query"]=> string(5) "query" ["fragment"]=> string(8) "fragment" }
Output for 5.3.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/ivtDX on line 20
Process exited with code 255.
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.2.17
Parse error: syntax error, unexpected T_STRING in /in/ivtDX on line 3
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_STRING in /in/ivtDX on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/ivtDX on line 3
Process exited with code 255.