PHP REGEX: Get domain from URL

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

    This is like the regex from theraccoonbear but with support for HTTPS domains.

    if (preg_match('/https?:\/\/([^\/]+)\//i', $target_string, $matches)) {
      $domain = $matches[1];
    }
    

提交回复
热议问题