title: Get domain (without TLD) using PHP
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/288810/get-the-subdomain-from-a-url">Get the subdomain from a URL</a>  </p>
  </blockquote>
  
  
  
  <p>I have seen posts about using parse_url to get www.domain.tld but how can i just get "domain" using php?</p>
  
  <p>i have got this regex currently</p>
  
  <pre><code>$pattern = '@https?://[a-z]{1,}\.{0,}([a-z]{1,})\.com(\.[a-z]{1,}){0,}@';
  </code></pre>
  
  <p>but this only works with .com and i need it to work with all TLDs (.co.uk, .com , .tv etc.)</p>
  
  <p>Is there a reliable way to do this, i am not sure if regex is the best way to go or not? or maybe explode on "." but then again subdomains would mess it up.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>so the desired outcome would be</p>
  
  <pre><code>$url = "https://stackoverflow.com/questions/11952907/get-domain-without-tld-using-php#comment15926320_11952907";
  
  $output = "stackoverflow";
  </code></pre>
  
  <p>Doing more research would anyone advise using parse_url to get www.domain.tld then using explode to get domain?</p>