How to use parse_url in php to parse URL and return its components
This article is about how to use parse_url to parse URL to return its components in php. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Parse_url
(PHP 4, PHP 5)
Parse_url-parses the URL and returns 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 a given URL, but to decompose it into the parts listed below. Incomplete URL is also accepted, and parse_url () will try to parse it as correctly as possible.
Parameters.
Url
URL to be parsed
Return value
For seriously unqualified URL,parse_url (), it may return FALSE and issue E_WARNING. Otherwise, an associative array is returned with at least one component:
Scheme-such as http
Host
Port
User
Pass
Path
Query-in the question mark? After that
Fragment-after the hash symbol #
Example
Example 2369. Parse_url () example
The above example outputs:
Array ([scheme] = > http [host] = > hostname [user] = > username [pass] = > password [path] = > / path [query] = > arg=value [fragment] = > anchor)
Annotation
Note: this function cannot be used for relative URL.
Note: parse_url () is specifically used to parse URL rather than URI. However, to comply with the need for PHP backward compatibility, three slashes (file:///...) are allowed for the file:// protocol. No other agreement can do that.
Thank you for reading! This is the end of this article on "how to use parse_url to parse URL to return its components in php". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!