title: How to get the first subdomain with PHP?
body: <p>I have a static domain of <code>dev.example.com</code> with wildcard subdomains like so <code>*.dev.example.com</code>.</p>
  
  <p>I need to detect the name of the current wildcard subdomain. So if I'm browsing <code>sub.dev.example.com</code> how do I get "sub"?</p>
  
  <pre><code>$env_domain = dev.example.com;
  $subdomain = array_shift( explode( '.', $_SERVER['HTTP_HOST'] ) ) .'.'. $env_domain;
  echo $subdomain;
  </code></pre>
  
  <p>Currently, this returns <code>dev</code>. I need it to return <code>sub</code>.</p>
  
  <p>I'm thinking the best practice here would be to return the most low-level domain (the first subdomain).</p>
  
  <p>Note that I'm not parsing a URL, but a given domain.</p>