Search code examples
phpcodeigniterget

PHP get whole string not individual params in URL


If I have a domain e.g. www.example.com/w/

I want to be able to get the whole string of text appended after the URL, I know how to get parameters in format ?key=value, that's not what I'm looking for.

but I would like to get everything after the /w/ prefix, the whole string altogether so if someone appended after the above

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

I would be able to get https://www.nytimes.com/2019/04/17/us/politics/trump-mueller-report.html

I was thinking of installing codeigniter on my server if that helps, but at the moment I'm just using core php


Solution

  • You just need to use 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;
    

    Output

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

    Read more about str_replace()