gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 06:33:50 25 4
gpt4 key购买 nike

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com