@ 2013-11-28T12:26:28Z <?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;
}
print_r($matches);
if ($flags & PHP_URL_REQUIRE_SCHEME) {
if (!isset($matches['scheme']) || $matches['scheme'] === '') {
return false;
}
}
if ($flags & PHP_URL_DISALLOW_EMPTY_AUTHORITY) {
if (isset($matches['hasauthority']) && $matches['hasauthority'] && (!isset($matches['host']) || $matches['host'] === '')) {
return false;
}
}
// Default to all components, allowing the above flags
// to be specified without specifying the components
$flags = $flags & PHP_URL_ALL ?: PHP_URL_ALL;
$result = [];
foreach ($map as $flag => $component) {
if (($flags & $flag) && isset($matches[$component]) && $matches[$component] !== '') {
$result[$component] = $flag === PHP_URL_PORT ? (int) $matches[$component] : $matches[$component];
}
}
return count($result) === 1 ? end($result) : $result;
}
parse_url('scheme://user:pass@host:12345/path?query#fragment');
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Output for 8.0.0 - 8.0.30 , 8.1.0 - 8.1.28 , 8.2.0 - 8.2.18 , 8.3.0 - 8.3.6 Array
(
[0] => scheme://user:pass@host:12345/path?query#fragment
[1] => scheme
[2] => user
[3] => pass
[4] => host
[5] => 12345
[6] => /path
[7] => query
[8] => fragment
)
Fatal error: Uncaught TypeError: Unsupported operand types: int & string in /in/M9Kkn:50
Stack trace:
#0 /in/M9Kkn(58): NotGlobal\parse_url('scheme://user:p...')
#1 {main}
thrown in /in/M9Kkn on line 50
Process exited with code 255 . Output for 7.1.0 - 7.1.20 , 7.2.0 - 7.2.33 , 7.3.12 - 7.3.33 , 7.4.0 - 7.4.33 Array
(
[0] => scheme://user:pass@host:12345/path?query#fragment
[1] => scheme
[2] => user
[3] => pass
[4] => host
[5] => 12345
[6] => /path
[7] => query
[8] => fragment
)
Warning: A non-numeric value encountered in /in/M9Kkn on line 50
Warning: A non-numeric value encountered in /in/M9Kkn on line 50
Warning: A non-numeric value encountered in /in/M9Kkn on line 50
Warning: A non-numeric value encountered in /in/M9Kkn on line 50
Warning: A non-numeric value encountered in /in/M9Kkn on line 50
Warning: A non-numeric value encountered in /in/M9Kkn on line 50
Warning: A non-numeric value encountered in /in/M9Kkn on line 50
Warning: A non-numeric value encountered in /in/M9Kkn on line 50
Output for 5.4.0 - 5.4.45 , 5.5.0 - 5.5.38 , 5.6.0 - 5.6.28 , 7.0.0 - 7.0.20 Array
(
[0] => scheme://user:pass@host:12345/path?query#fragment
[1] => scheme
[2] => user
[3] => pass
[4] => host
[5] => 12345
[6] => /path
[7] => query
[8] => fragment
)
Output for 5.3.0 - 5.3.29 Parse error: syntax error, unexpected '[' in /in/M9Kkn on line 20
Process exited with code 255 . Output for 4.4.2 - 4.4.9 , 5.1.0 - 5.1.6 , 5.2.0 - 5.2.17 Parse error: syntax error, unexpected T_STRING in /in/M9Kkn on line 3
Process exited with code 255 . Output for 4.3.0 - 4.3.1 , 4.3.5 - 4.3.11 , 4.4.0 - 4.4.1 , 5.0.0 - 5.0.5 Parse error: parse error, unexpected T_STRING in /in/M9Kkn on line 3
Process exited with code 255 . Output for 4.3.2 - 4.3.4 Parse error: parse error in /in/M9Kkn on line 3
Process exited with code 255 . preferences:dark mode live preview
235.18 ms | 401 KiB | 357 Q