The function ip2long() generates an IPv4 Internet network address from its Internet standard format (dotted string) representation. If ip_address is invalid then -1 is returned. Note that -1 does not evaluate as FALSE in PHP. As of PHP 5.0.0 ip2long() returns FALSE when ip_address is invalid.ip2long() will also work with non-complete IP addresses,It means 25.108.9 is the same as 25.108.9.0
print "Invalid";
}
<?php
if ( !ip2long("25.108.9") ) {
print "Invalid";
}
else{
print "Valid";
}
?>
这样输出是Valid
$ip = "255.12.26.25";echo is_ip($ip);//试function is_ip($ip){
if(!strcmp(long2ip(sprintf('%u',ip2long($ip))),$ip)) {
return "正确的IP";
} else {
return "错误的IP";
}
}
?>
http://www.regexlab.com/zh/workshop.asp?pat=%5Cb%28%28%28%3F%21%5Cd%5Cd%5Cd%29%5Cd%2B%7C1%5Cd%5Cd%7C2%5B0-4%5D%5Cd%7C25%5B0-5%5D%29%28%5Cb%7C%5C.%29%29%7B4%7D&txt=202.108.9.16%0D%0A257.108.9.16%0D%0A192.168.0.1%2C%2010.0.0.255%2C%20211.100.0.0%20%20%0D%0A192.256.0.1%2C%2010.0.0.256%2C%20211.100.0.1000&dlt=0编写方法:
http://www.regexlab.com/zh/regref.htm
http://www.nanocn.net/bbs/viewthread.php?tid=2