Php obtains the summary of url parameter program code. The parse_url function first describes the parse_url function. The official solution is mixedparse_url (string $ url [, int $ component-1]). This function parses a URL and returns an associated parse_url function.
Let's take a look at the parse_url function.
Description
Mixed parse_url (string $ url [, int $ component =-1])
This function parses a URL and returns an associated array, which contains various components in the URL.
This function is not used to verify the validity of a given URL, but is used to separate it into the parts listed below. Incomplete URLs are also accepted, and parse_url () tries to parse them correctly as much as possible.
The URL to be parsed. Invalid characters are replaced.
Instance
| The code is as follows: |
|
|
$ Url = "http://www.45it.net/welcome ";
$ Parts = parse_url ($ url );
Print_r ($ parts );
Array
(
[Scheme] => http
[Host] => www.45it.net
[Path] =>/welcome/
)
|
You can also write an algorithm on your own! As follows:
| The code is as follows: |
|
|
Function getParams ()
{
$ Url = '/index. php? _ P = index & _ a = show & x = 12 & y = 23 ';
$ Refer_url = parse_url ($ url );
$ Params = $ refer_url ['query'];
$ Arr = array ();
If (! Empty ($ params ))
{
$ ParamsArr = explode ('&', $ params );
Foreach ($ paramsArr as $ k => $ v)
{
$ A = explode ('=', $ v );
$ Arr [$ a [0] = $ a [1];
}
}
Return $ arr;
}
|
Call method
| The code is as follows: |
|
|
$ Arr = getParams ();
Print_r ($ arr ); |
Result
Result: Array ([_ p] => index [_ a] => show [x] => 12 [y] => 23)
For details, refer to the parse_url function. The official solution is mixed parse_url (string $ url [, int $ component =-1]). This function parses a URL and returns an association...