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

时间:2019-04-18 03:53:32

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

2 个答案:

答案 0 :(得分:2)

您只需要使用let ulElem = document.createElement("ul"); for (let i = 0; i < 4; i++) { let liElem = document.createElement("li"); let textNode = document.createTextNode("this is li"); liElem.appendChild(textNode); ulElem.appendChild(liElem); } // ulElem now has 4 children of li

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;

详细了解str_replace()

答案 1 :(得分:1)

尝试使用strpossubstr

$str = "www.example.com/w/https://www.nytimes.com/2019/04/17/us/politics/trump-mueller-report.html";
echo $str.'<pre>';
$start =  strpos($str, '/w/');
echo substr($str, $start + 3);die;

输出:

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
  

strpos()将使您第一次出现/w/,然后可以用+3进行替换以删除/w/

或尝试使用strstrstr_replace

$str = "www.example.com/w/https://www.nytimes.com/2019/04/17/us/politics/trump-mueller-report.html";
echo $str.'<pre>';
$str1 =  strstr($str, '/w/');
echo $str1.'<pre>';
$str2 = str_replace('/w/', '', $str1);
echo $str2.'<pre>';die;

输出:

www.example.com/w/https://www.nytimes.com/2019/04/17/us/politics/trump-mueller-report.html

/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
  

strstr()将为您提供给定/w/的子字符串,并使用str_replace()从新字符串中删除/w/