PHP从URL变量获取域名后的所有内容

Rad*_*duS 2 php url

我有一个存储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)

ins*_*ns0 9

看看php的功能parse_urlparse_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)