Example user input
http://domain.com/
http://domain.com/topic/
http://domain.com/topic/cars/
http://www.domain.com/topic/questions/
I want
I'd suggest using the tools PHP gave you, have a look at parse_url.
The above example will output:
Array
(
[scheme] => http
[host] => hostname
[user] => username
[pass] => password
[path] => /path
[query] => arg=value
[fragment] => anchor
)
/path
It sounds like you're after at least host + path (add others as needed, e.g. query):
$parsed = parse_url('http://www.domain.com/topic/questions/');
echo $parsed['host'], $parsed['path'];
> www.domain.com/topic/questions/
Cheers