PHP REGEX: Get domain from URL

前端 未结 9 1923
情歌与酒
情歌与酒 2020-12-08 11:05

What I want


I want to get from a URL the domain part so from http://example.com/ -> example.com

9条回答
  •  清歌不尽
    2020-12-08 11:13

    I use:

    $domain = parse_url('http://' . str_replace(array('https://', 'http://'), '', $url), PHP_URL_HOST);
    

    Because parse_url doesn't return host key when schema is missing in $url.

提交回复
热议问题