Get subdomain if any
<p>Is there any predefined method in PHP to get sub-domain from url if any?</p>

<p>url pattern may be:</p>

<pre><code>http://www.sd.domain.com
http://domain.com
http://sd.domain.com
http://domain.com
</code></pre>

<p>where sd stands for sub-doamin.</p>

<p>Now method must return different values for every case:</p>

<blockquote>
  <p><strong>case 1</strong> -> return <strong>sd</strong></p>
  
  <p><strong>case 2</strong> -> return <strong>false</strong> or <strong>empty</strong></p>
  
  <p><strong>case 3</strong> -> return <strong>sd</strong></p>
  
  <p><strong>case 4</strong> -> return <strong>false</strong> or <strong>empty</strong></p>
</blockquote>

<p>I found some good links</p>

<p><a href="http://stackoverflow.com/questions/5292937/php-function-to-get-the-subdomain-of-a-url">PHP function to get the subdomain of a URL</a></p>

<p><a href="http://stackoverflow.com/questions/12997473/get-subdomain-from-url">Get subdomain from url?</a></p>

<p>but not specifically apply on my cases.</p>

<p>Any help will be most appreciable.</p>

<p>Thanks</p>
