How to get Base URL from string?

How to get Base URL from string?

I need to get the base url. The domain name only from a string?

say the domain is http://domain.com/test/test.php?id=1234123

I just want it to show http://domain.com does anyone know a way of doing this via php?

Thanks
Mike Koenig

print 'http://' . $_SERVER['HTTP_HOST'];

Thanks thanks. :slight_smile: Quick service with a smile.

If you’re looking to extract it from a string that’s not the currently executing scripts address, you can use parse_url to get an array like this.

Array
(
    [scheme] => http
    [host] => hostname
    [user] => username
    [pass] => password
    [path] => /path
    [query] => arg=value
    [fragment] => anchor
)