Parse_url function
Let's take a look at the Parse_url function, the official solution
Description
Mixed Parse_url (string $url [, int $component =-1])
This function resolves a URL and returns an associative array containing the various components that appear in the URL.
This function is not used to verify the legality of a given URL, but to decompose it into the sections listed below. An incomplete URL is also accepted, and Parse_url () tries to parse it as correctly as possible.
The URL to resolve. Invalid characters will be replaced with _.
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 yourself!
| 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); |
Results
Result: Array ([_p] => index [_a] => Show [x] => [y] =>)