title: Get domain name (not subdomain) in php
body: <p>I have a URL which can be any of the following formats:</p>
  
  <pre><code>http://example.com
  https://example.com
  http://example.com/foo
  http://example.com/foo/bar
  www.example.com
  example.com
  foo.example.com
  www.foo.example.com
  foo.bar.example.com
  http://foo.bar.example.com/foo/bar
  example.net/foo/bar
  </code></pre>
  
  <p>Essentially, I need to be able to match any normal URL. How can I extract <code>example.com</code>  (or .net, whatever the tld happens to be. I need this to work with any TLD.) from all of these via a single regex? </p>