|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2003-10-08 07:32 UTC] gmirchev at usa dot net
[2003-10-08 08:01 UTC] wez@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Nov 30 04:00:01 2025 UTC |
Description: ------------ parse_url does not correctly handle these relative URLs: a.cgi?keywords=6:54+ a.cgi?keywords=6:54 In the reproduce code is correct PHP implementation. Reproduce code: --------------- function url_parse($url) { $parts = array( 'scheme' => '', 'host' => '', 'port' => '', 'user' => '', 'pass' => '', 'path' => '', 'query' => '', 'fragment' => '' ); # Regular Expression from RFC 2396 (appendix B) preg_match('"^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?"', $url, $matches); if (array_key_exists(2, $matches)) $parts['scheme'] = $matches[2]; if (array_key_exists(4, $matches)) $authority = $matches[4]; if (array_key_exists(5, $matches)) $parts['path'] = $matches[5]; if (array_key_exists(7, $matches)) $parts['query'] = $matches[7]; if (array_key_exists(9, $matches)) $parts['fragment'] = $matches[9]; # Extract username, password, host and port from authority preg_match('"(([^:@]*)(:([^:@]*))?@)?([^:]*)(:(.*))?"', $authority, $matches); if (array_key_exists(2, $matches)) $parts['user'] = $matches[2]; if (array_key_exists(4, $matches)) $parts['pass'] = $matches[4]; if (array_key_exists(5, $matches)) $parts['host'] = $matches[5]; if (array_key_exists(7, $matches)) $parts['port'] = $matches[7]; return $parts; }