phpWhois.org/generic3.whois
2003-03-17 09:38:47 +00:00

168 lines
3.7 KiB
Text

<?php
/*
Generic3.php PHP functions for parsing whois output
Copyright (C)2003
Maintained by Mark Jeftovic <markjr@easydns.com>
For the most recent version of this package:
http://www.easydns.com/~markjr/whois2/
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
function get_blocks ( $rawdata, $items )
{
$endtag="";
while (list($field, $match)=each($items))
{
// search block header
reset($rawdata);
$found=false;
while (list($key,$val)=each($rawdata))
{
$pos=strpos($val,$match);
if ($pos!==false)
{
$last=substr(trim($val),-1,1);
if ($last==":" || $last=="-" || $last=="]")
{
$found=true;
$endtag=$last;
break;
}
else {
$var=getvarname(strtok($field,"#"));
$itm=trim(substr($val,$pos+strlen($match)));
eval($var."=\$itm;");
}
}
}
if (!$found) continue;
$block=array();
$found=false;
while (list($key,$val)=each($rawdata))
{
$val=trim($val);
if ($val=="")
{ if ($found) break;
else continue;
}
$found=true;
$last=substr(trim($val),-1,1);
//if ($last==":" || $last=="-") break;
if ($last==$endtag) break;
$block[]=$val;
}
$var=getvarname($field);
eval($var."=\$block;");
}
return $r;
}
function getvarname ( $vdef )
{
$parts=explode(".",$vdef);
$var="\$r";
while (list($fn,$mn)=each($parts))
if ($mn=="")
$var=$var."[]";
else $var=$var."[\"".$mn."\"]";
return $var;
}
function get_contact ( $array )
{
$items = array (
"phone:" => "phone",
"fax..:" => "fax",
"fax-" => "fax",
"fax:" => "fax",
"email:" => "email"
);
while (list($key,$val)=each($array))
{
reset($items);
while (list($match,$field)=each($items))
{
$pos=strpos(strtolower($val),$match);
if ($pos===false) continue;
$itm=trim(substr($val,$pos+strlen($match)));
$r[$field]=$itm;
$val=trim(substr($val,0,-strlen($itm)-1-strlen($match)));
if ($val=="")
unset($array[$key]);
else $array[$key]=$val;
break;
}
if ($val=="") continue;
if (!preg_match("/[^0-9\(\)\-\.\+ ]/", $val))
{
if (isset($r["phone"]))
$r["fax"]=$val;
else $r["phone"]=$val;
unset($array[$key]);
continue;
}
if (strstr($val,"@"))
{
$parts=explode(" ",$val);
$top=count($parts)-1;
$r["email"]=$parts[$top];
array_pop($parts);
$val=implode(" ",$parts);
if ($val=="") {
unset($array[$key]);
continue;
}
$r["name"]=$val;
unset($array[$key]);
if ($key==1)
{
$r["organization"]=$array[0];
unset($array[0]);
}
}
}
if (!isset($r["name"]))
{
$r["name"]=$array[0];
unset($array[0]);
}
$r["address"]=$array;
return $r;
}
?>