Try this:

function padIP($ip){
  $ar = explode(".",$ip);
  $ip = "";
  $xt = "";
  for ($i = 0; $i<count($ar); $i++){
    $ip .= $xt.substr(($ar[$i]+1000),1);
    $xt = ".";
  return $ip;

-----Original Message-----
From: Wilmar Perez [mailto:[EMAIL PROTECTED]]
Sent: Thursday, September 26, 2002 10:40 AM
Subject: [PHP-DB] Valid IP

Hello guys

I know this should be asked in another list but don't want to subcribe just 
for a simple question.  I apologise in advance if that bothers anyone.

I'm trying to check valid IPs that come from a form filled by a user so I'm 
using the following:

function valid_ip($ip)
//Check whether it is a valid IP
    if (ereg("^[1-9]{2,3}+\.[1-9]{2,3}+\.[1-9]{2,3}+\.[1-9]{2,3}+$", $ip))
        return true;
        return false;

However it just accepts IPs such as  Errors arise whith IP 
such as that is every part of the IP should be 3 numbers 
lenght to be accepted making the function not very handy.

Any idea?

                         Wilmar Pérez
                     Network Administrator
                       Library System
                      Tel: ++57(4)2105145
                    University of Antioquia
                       Medellín - Colombia

PHP Database Mailing List (
To unsubscribe, visit:

PHP Database Mailing List (
To unsubscribe, visit:

Reply via email to