Parsing domain from a URL

前端 未结 18 2479
独厮守ぢ
独厮守ぢ 2020-11-22 12:26

I need to build a function which parses the domain from a URL.

So, with

http://google.com/dhasjkdas/sadsdds/sdda/sdads.html

or

18条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-22 12:29

    $domain = str_ireplace('www.', '', parse_url($url, PHP_URL_HOST));
    

    This would return the google.com for both http://google.com/... and http://www.google.com/...

提交回复
热议问题