Looking for a way to get the path from a URL in PHP:
I want to take: http://example.com/hurrdurr
http://example.com/hurrdurr
And do it: hurrdurr
hurrdurr
I need text only after .com/
.com/
Can I do this with cropping?
Use parse_url to extract the information you need.
parse_url
For instance:
$url = "http://twitter.com/pwsdedtch"; $path = parse_url($url, PHP_URL_PATH); // gives "/pwsdedtech" $pathWithoutSlash = substr($path, 1); // gives "pwsdedtech"
In this particular case, you can also use "basename" for your own purposes.
$var='http://twitter.com/pwsdedtch'; echo basename($var); // pwsdedtech