if ( ip2long("202.108.9.16") ) {
  print "Valid";
}
if ( ip2long("257.108.9.16") ) {
  print "Invalid";
}

解决方案 »

  1.   

    if ( !ip2long("257.108.9.16") ) {
      print "Invalid";
    }
      

  2.   

    貌似不太可靠
    <?php
    if ( !ip2long("25.108.9") ) {
       print "Invalid";
    }
    else{
    print "Valid";
    }
    ?> 
    这样输出是Valid
      

  3.   

    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
      

  4.   

    <?php
    $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";
    }

    ?>
      

  5.   

    ip2long不好用,还是best_inh(一无所) 的好用
      

  6.   

    我觉得要是在网页里提示IP不对的话,不如用js
      

  7.   

    \b(((?!\d\d\d)\d+|1\d\d|2[0-4]\d|25[0-5])(\b|\.)){4}测试页面:(推荐)
    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
      

  8.   

    这样的问题到google一艘一大堆啊!
      

  9.   

    /* returns true if $ipaddr is a valid dotted IPv4 address */我的WEB程序中写过的一个函数,见:
    http://www.nanocn.net/bbs/viewthread.php?tid=2