phpurltext-extractionsanitizationurl-parsing

Get the host substring from a URL string


I'm using PHP/Symfony2 and need to get the host substring from a URL string.

Possible input:

http://some.url/

Desired output (without schema and slashes):

some.url

The simplest solution is str_replace(["http://", "https://", "/"], ['','', ''], 'http://some.url'); but I don't like it.


Solution

  • there is builtin php function doc:

    $domain = parse_url($url, PHP_URL_HOST);