some useful improvments

This commit is contained in:
sparc 2003-02-18 19:11:20 +00:00
parent 54e8850c75
commit b40c7d5462

View file

@ -54,11 +54,16 @@ while (list($field, $match)=each($items))
if (!$found) continue; if (!$found) continue;
$block=array(); $block=array();
$found=false;
while (list($key,$val)=each($rawdata)) while (list($key,$val)=each($rawdata))
{ {
$val=trim($val); $val=trim($val);
if ($val=="") break; if ($val=="")
{ if ($found) break;
else continue;
}
$found=true;
$last=substr(trim($val),-1,1); $last=substr(trim($val),-1,1);
if ($last==":" || $last=="-") break; if ($last==":" || $last=="-") break;
$block[]=$val; $block[]=$val;
@ -87,19 +92,33 @@ return $var;
function get_contact ( $array ) function get_contact ( $array )
{ {
$items = array (
"phone:" => "phone",
"fax..:" => "fax",
"fax:" => "fax",
"email:" => "email"
);
while (list($key,$val)=each($array)) while (list($key,$val)=each($array))
{ {
$pos=strpos(strtolower($val),"fax:"); reset($items);
if ($pos!==false)
{ while (list($match,$field)=each($items))
$itm=trim(substr($val,$pos+4)); {
$r["fax"]=trim($itm); $pos=strpos(strtolower($val),$match);
$val=trim(substr($val,0,-strlen($itm)-5)); if ($pos===false) continue;
if ($val=="") $itm=trim(substr($val,$pos+strlen($match)));
unset($array[$key]); $r[$field]=$itm;
else $array[$key]=$val; $val=trim(substr($val,0,-strlen($itm)-1-strlen($match)));
} if ($val=="")
if ($val!="" && !preg_match("/[^0-9\(\)\-\. ]/", $val)) unset($array[$key]);
else $array[$key]=$val;
break;
}
if ($val=="") continue;
if (!preg_match("/[^0-9\(\)\-\. ]/", $val))
{ {
if (isset($r["phone"])) if (isset($r["phone"]))
$r["fax"]=$val; $r["fax"]=$val;