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

标签 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"

我如何提取域名后的所有内容。例如我想从

$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_urlparse_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/

相关文章:

javascript - OwlCarousel2 更新拖动时的 URL 哈希导航

javascript - 可用性日历 - 最高效 - PHP/MySql/JavaScript

python - Django 2.0 的 Django 奥斯卡 URL?

javascript - 向现有 href 添加额外文本

html - 获取 HTML/cshtml 中的 URL

php - 调整注销功能以处理 Safari 后退按钮问题

php - 如何在 NetBeans 中生成 PHP getter 和 setter?

Apache 8.5 拒绝编码的 url

c# Convert.To Base64(String) 没有脉冲

javascript - 通过 Enter 键和提交按钮提交表单