Home > Backend Development > PHP Tutorial > Discussion: parse url parses the URL and returns its components_PHP tutorial

Discussion: parse url parses the URL and returns its components_PHP tutorial

WBOY
Release: 2016-07-21 15:06:35
Original
719 people have browsed it

parse_url
(PHP 4, PHP 5)
parse_url — Parse a URL and return its components
Description
array parse_url ( string $url )
This function parses a URL and returns an associative array containing the various components that appear in the URL.
This function is not used to verify the validity of the given URL, but to break it down into the parts listed below. Incomplete URLs are also accepted and parse_url() will try to parse them as correctly as possible.

Parameters
url
The URL to be parsed
Return value
For severely unqualified URLs, parse_url() may return FALSE and issue E_WARNING. Otherwise, an associative array is returned whose components are (at least one):

scheme - such as http
host
port
user
pass
path
query - after the question mark?
fragment - after the hash symbol #
Example
Example 2369. parse_url() Example
$url = 'http://username:password@hostname/path?arg=value#anchor';
print_r(parse_url($url));
?>
The above example will output:
Array( [scheme] => http [host] => hostname [user] => username [pass] => password [path] => /path [ query] => arg=value [fragment] => anchor)
Comments
Note: This function cannot be used for relative URLs.
Note: parse_url() is specifically used to parse URLs rather than URIs. However, there is an exception to comply with PHP backward compatibility needs, and three slashes are allowed for the file:// protocol (file:///...). No other agreement can do this.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/327614.htmlTechArticleparse_url (PHP 4, PHP 5) parse_url — Parse the URL and return its component description array parse_url ( string $url ) This function parses a URL and returns an associative array, contained in U...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template