How to get the first subdomain with PHP?

前端 未结 5 842
广开言路
广开言路 2020-12-11 23:10

I have a static domain of dev.example.com with wildcard subdomains like so *.dev.example.com.

I need to detect the name of the current wild

5条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-11 23:24

    Here's a little function that'll do the trick. Just stick $_SERVER['HTTP_HOST'] into the function and you should get what you want

    function getSubDomain ($domain) {
        $eDom = explode('.', $domain);
        return $eDom[0];
    }
    
    echo getSubDomain('sub.dev.example.com'); // echo 'sub' 
    

提交回复
热议问题