I want to find the true hostname from the "host" returned by parse_url. In Unix / Linux / TCP/IP, a host's name is " from the hostname "
I had the regex working, but I also needed to filter out any bozos who would erroenously enter "try.to.break.the.url. Again, I want to match/select the " hostname and can do without the rest. I thought that this code would work, but it doesn't.
Maybe some fresh eyes will spot my error. Thanks.
<?php
function real_host ($host=""
{
if (! $host) {return (""
;}
// This regex pair is belt-and-suspenders redundancy from
// my debug efforts. The first one should be sufficient
// to filter out bogus prefix's on the hostname, but it
// doesn't get the job done.....
if (preg_match("/^.*?\.?(.*)\.(.*)\.(.*)$/",$host,$matches))
{ if (preg_match("/^.*?\.?(.*)$/",$matches[1],$final))
{return $final[1];}
}
return (""
;
}
$arr="";
// My objective is to return " from function real_host
$arr=parse_url(strtolower("print_r($arr);
print "<br>\n";
print real_host($arr["host"]);
?>
Surfinbox.com Business Internet Services - National Dialup, DSL, T-1 and more.
I had the regex working, but I also needed to filter out any bozos who would erroenously enter "try.to.break.the.url. Again, I want to match/select the " hostname and can do without the rest. I thought that this code would work, but it doesn't.
Maybe some fresh eyes will spot my error. Thanks.
<?php
function real_host ($host=""

if (! $host) {return (""

// This regex pair is belt-and-suspenders redundancy from
// my debug efforts. The first one should be sufficient
// to filter out bogus prefix's on the hostname, but it
// doesn't get the job done.....
if (preg_match("/^.*?\.?(.*)\.(.*)\.(.*)$/",$host,$matches))
{ if (preg_match("/^.*?\.?(.*)$/",$matches[1],$final))
{return $final[1];}
}
return (""

}
$arr="";
// My objective is to return " from function real_host
$arr=parse_url(strtolower("print_r($arr);
print "<br>\n";
print real_host($arr["host"]);
?>
Surfinbox.com Business Internet Services - National Dialup, DSL, T-1 and more.