Parsing domain from a URL

前端 未结 18 2203
独厮守ぢ
独厮守ぢ 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:37

    You can pass PHP_URL_HOST into parse_url function as second parameter

    $url = 'http://google.com/dhasjkdas/sadsdds/sdda/sdads.html';
    $host = parse_url($url, PHP_URL_HOST);
    print $host; // prints 'google.com'
    

提交回复
热议问题