我有一个存储 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"
我如何提取域名后的所有内容。例如我想从
$link = "https://www.google.no/search?num=100&newwindow=1&safe=off&site=&source=hp&q=example&oq=example"
提取
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"
提取
/forums/showthread.php?37dsf624-Get-everything-after-the-domain-name
最佳答案
查看php函数parse_url
和parse_str
http://php.net/manual/de/function.parse-url.php
http://php.net/manual/de/function.parse-str.php
你可以用这个从你的 url 中提取所有内容。
$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
)
关于PHP 从 URL 变量中获取域名后的所有内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24843906/