The example in this article describes the method of obtaining url parameters in PHP. Share it with everyone for your reference. The details are as follows:
There are many ways to get the parameters in the url in php. The simplest one is to directly use the parse_url function. It can automatically parse the url parameters and values conveniently and quickly and save them in the corresponding array. Others One method is basically based on regular expressions.
parse_url function
Let’s first understand the parse_url function, the official solution
Description:
mixed parse_url ( string $url [, int $component = -1 ] )
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, only to break it into the parts listed below. Incomplete URLs are also accepted and parse_url() will try to parse them as correctly as possible.
The URL to parse. Invalid characters will be replaced with _.
Examples are as follows:
array
(
[scheme] => http
[host] => www.jb51.net
[path] => /welcome/
)
The running results are as follows:
I hope this article will be helpful to everyone’s PHP programming design.