|
Posted by deko on 12/17/68 11:56
I'm sure someone has passed this way before...
I want to check to see is a domain name is contained in a string, and if one is,
I want to extract it. In these strings, domains are always preceded by
"http://" or "http : //www" (without the spaces).
in pseudo code, I thought it might look like this:
if (eregi("http: //", $mystring))
{
$domain = explode("http: //", $mystring);
$domain = array_reverse($domain);
}
$parts = domain[0];
explode(".", $parts);
if ($parts[0] == "www")
{
$extracted = $parts[1]."."$parts[2];
}
else
{
$extracted = $parts[0]."."$parts[1];
}
Does this look about right?
Thanks in advance.
[Back to original message]
|