我有一个存储URL链接的变量,例如:
$link = "https://www.google.no/search?num=100&newwindow=1&safe=off&site=&source=hp&q=example&oq=example"
$link = "http://www.example.com/forums/showthread.php?37dsf624-Get-everything-after-the-domain-name"
Run Code Online (Sandbox Code Playgroud)
我如何提取域名之后的evrything.例如,我想要
$link = "https://www.google.no/search?num=100&newwindow=1&safe=off&site=&source=hp&q=example&oq=example"
Run Code Online (Sandbox Code Playgroud)
提取
search?num=100&newwindow=1&safe=off&site=&source=hp&q=example&oq=example
Run Code Online (Sandbox Code Playgroud)
从
$link = "http://www.example.com/forums/showthread.php?37dsf624-Get-everything-after-the-domain-name"
Run Code Online (Sandbox Code Playgroud)
提取
/forums/showthread.php?37dsf624-Get-everything-after-the-domain-name
Run Code Online (Sandbox Code Playgroud)
看看php的功能parse_url和parse_str
http://php.net/manual/de/function.parse-url.php
http://php.net/manual/de/function.parse-str.php
你可以从你的网址中提取所有内容.
$link = "https://www.google.no/search?num=100&newwindow=1&safe=off&site=&source=hp&q=example&oq=example";
$parsedUrl = parse_url($link);
parse_str($parsedUrl['query'], $parsedQuery);
print_r($parsedUrl);
print_r($parsedQuery);
Array
(
[scheme] => https
[host] => www.google.no
[path] => /search
[query] => num=100&newwindow=1&safe=off&site=&source=hp&q=example&oq=example
)
Array
(
[num] => 100
[newwindow] => 1
[safe] => off
[site] =>
[source] => hp
[q] => example
[oq] => example
)
Run Code Online (Sandbox Code Playgroud)