|
Posted by deko on 11/21/60 11:57
Thanks for the tip on parse_url.
But I still have to find the URL (which could be anywhere) in the string.
> Without the spaces? Then, why do you add the spaces?
Here's a psuedocode example without the spaces:
if (eregi("http://", $mystring))
{
$mystring = explode("http://", $mystring);
$mystring = array_reverse($mystring);
$domain = $mystring[0];
$domain = explode(".", $domain);
if ($domain[0] == "www")
{
$extracted = $domain[1].".".$domain[2];
}
else
{
$extracted = "$domain[0].".".$domain[1];
}
}
Would it be better to use preg_match here?
preg_match('@^(?:http://)?([^/]+)@i',
"http://www.php.net/index.html", $matches);
$host = $matches[1];
// get last two segments of host name
preg_match('/[^.]+\.[^.]+$/', $host, $matches);
echo "domain name is: {$matches[0]}\n";
But would this work if the URL is buried in a string?
Navigation:
[Reply to this message]
|