PHP 获取整个字符串而不是 URL 中的单个参数

标签 php codeigniter get

如果我有一个域名,例如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/

相关文章:

php - Codeigniter - if else 内部 View

php - 如何在codeigniter中定义全局变量?

javascript - 如何修复 GET URL 中更改的日期格式

php - 无法识别的配置参数 "dynamic_shared_memory_type"

php - 加入 Propel 导致递归警告

javascript - JQuery 文件输入在本地有效,但在远程服务器上无效

get - 如何使用AngularJS删除GET参数?

php - 使用 php session 搜索数据库不会返回任何结果或错误

php - 如何处理介绍 friend 的数据?

php - Kohana、.htaccess 和 $_GET