Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove hostname from string using PHP?

Tags:

url

php

Can someone tell me how to strip anything that appears between http:// and /? For example, http://something/ or http://something.something.something/ so it changes to just /?

like image 418
Zoolander Avatar asked Nov 22 '12 01:11

Zoolander


1 Answers

Assuming you're working with a URL and not a long string containing a url...

$path = parse_url($url, PHP_URL_PATH);
like image 99
Adrian Schneider Avatar answered Sep 20 '22 22:09

Adrian Schneider