Parsing domain from a URL

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

    parse_url didn't work for me. It only returned the path. Switching to basics using php5.3+:

    $url  = str_replace('http://', '', strtolower( $s->website));
    if (strpos($url, '/'))  $url = strstr($url, '/', true);
    

提交回复
热议问题