title: PHP Getting Domain Name From Subdomain
body: <p>I need to write a function to parse variables which contain domain names. It's best I explain this with an example, the variable could contain any of these things:</p>
  
  <pre><code>here.example.com
  example.com
  example.org
  here.example.org
  </code></pre>
  
  <p>But when passed through my function all of these must return either example.com or example.co.uk, the root domain name basically. I'm sure I've done this before but I've been searching Google for about 20 minutes and can't find anything. Any help would be appreciated.</p>
  
  <p>EDIT: Ignore the .co.uk, presume that all domains going through this function have a 3 letter TLD.</p>