日期:2014-05-20  浏览次数:20785 次

求一个验证ipv4,ipv6,FQDN的方法
就是验证一个输入,既可以是ipv4,也可以是ipv6,还可以是合法的域名
谢谢!

------解决方案--------------------
//-------------------->IP地址验证--------------------
 function i_ip(){
if(!ereg("^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$", $this->var_value)){
$this->array_errors[$this->var_key]="错误的IP地址";
}else{
//每个不大于255
$array_temp=preg_split("/\./",$this->var_value);
foreach($array_temp as $ip_value){
if((int)$ip_value >255)
$this->array_errors[$this->var_key]="错误的IP地址";
}
}
return true;
 }