Omotayo
Omotayo

Reputation: 59

PHP Remove http and web domain from url

I want http and web domain removed in a url and render the rest

URL | Expected result

http://www.loadedcamp.net/images/featured/2017/06/1497262523-How_to_Avoid_Adultery_in_Your_Marriage.jpg | /images/featured/2017/06/1497262523-How_to_Avoid_Adultery_in_Your_Marriage.jpg

http://www.loadedcamp.net/music/63637-adele-hello | /music/63637-adele-hello

Upvotes: 2

Views: 2501

Answers (2)

RAUSHAN KUMAR
RAUSHAN KUMAR

Reputation: 6006

You can php parse_url() method to get the complete info of URL:

$foo = "http://www.loadedcamp.net/music/63637-adele-hello";
$blah = parse_url($foo);
print_r($blah);
Array
(
    [scheme] => http
    [host] => www.loadedcamp.net
    [path] => /music/63637-adele-hello
    [query] => 
)

print_r($blah['path']);

Outputs /music/63637-adele-hello

You can also use like this:

echo parse_url('http://www.loadedcamp.net/music/63637-adele-hello', PHP_URL_PATH);

Also outputs /music/63637-adele-hello

Upvotes: 3

Pascal Meunier
Pascal Meunier

Reputation: 715

Here with parse_url() function.

parse_url('http://www.loadedcamp.net/music/63637-adele-hello', PHP_URL_PATH);

Output: /music/63637-adele-hello

Upvotes: 4

Related Questions