<p>I need to build a function which parses the domain from a URL.</p>
<p>So, with</p>
<pre><code>http://google.com/dhasjkdas/sadsdds/sdda/sdads.html
</code></pre>
<p>or</p>
<pre><code>http://www.google.com/dhasjkdas/sadsdds/sdda/sdads.html
</code></pre>
<p>it should return <code>google.com</code></p>
<p>with</p>
<pre><code>http://google.co.uk/dhasjkdas/sadsdds/sdda/sdads.html
</code></pre>
<p>it should return <code>google.co.uk</code>.</p>

Check out
```
parse_url()
```
:
```
```
$url = 'http://google.com/dhasjkdas/sadsdds/sdda/sdads.html';
$parse = parse_url($url);
echo $parse['host']; // prints 'google.com'
```
```
```
parse_url
```
doesn't handle really badly mangled urls very well, but is fine if you generally expect decent urls.