如果我有一个域名,例如www.example.com/w/
我希望能够获取附加在 URL 之后的整个文本字符串,我知道如何获取格式为 ?key=value 的参数,这不是我想要的。
但我想获得/w/前缀之后的所有内容,整个字符串,所以如果有人在上面附加之后
www.example.com/w/https://www.nytimes.com/2019/04/17/us/politics/trump-mueller-report.html
我可以获得https://www.nytimes.com/2019/04/17/us/politics/trump-mueller-report.html
如果有帮助的话,我正在考虑在我的服务器上安装 codeigniter,但目前我只使用核心 php
最佳答案
您只需要使用str_replace()
$str = "www.example.com/w/https://www.nytimes.com/2019/04/17/us/politics/trump-mueller-report.html";
$str2 = str_replace('www.example.com/w/', '', $str);
echo $str2;
输出
https://www.nytimes.com/2019/04/17/us/politics/trump-mueller-report.html
了解更多关于str_replace()的信息
关于PHP 获取整个字符串而不是 URL 中的单个参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55738887/