PHP REGEX: Get domain from URL

前端 未结 9 1941
情歌与酒
情歌与酒 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:14

    There's no need to use a regex for this. PHP has an inbuilt function to do just this. Use parse_url():

    $domain = parse_url($url, PHP_URL_HOST);
    

提交回复
热议问题