KLin
KLin

Reputation: 479

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.

Upvotes: 0

Views: 39

Answers (1)

Sylvain Guilbert
Sylvain Guilbert

Reputation: 722

there is builtin php function doc:

$domain = parse_url($url, PHP_URL_HOST);

Upvotes: 4

Related Questions