2

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

1
  • check my answer Commented Jul 2, 2017 at 19:58

2 Answers 2

4

Here with parse_url() function.

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

Output: /music/63637-adele-hello

Sign up to request clarification or add additional context in comments.

Comments

3

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.