note 32772 deleted from function.is-numeric by pollita
| From: | pollita@php.net | Date: | Fri, 06 Jun 2003 15:52:45 +0000 |
| Subject: | note 32772 deleted from function.is-numeric by pollita | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-49887@lists.php.net to get a copy of this message | ||
Note Submitter: user@friendly.org
----
I've seen a couple of functions here that destinguish an IP from any other input. Although mine
isn't very different, it checks for...
- numeric input
- valid numbers (> 0 && < 256)
- 4 parts (111.222.333.444)
...and returns true or false.
<?
function is_ip($value)
{
$parts = split('\.', $value);
if(count($parts) == 4)
{
foreach($parts as $part)
{
if((!is_null($part)) && ($part < 0 || $part > 255) || !is_numeric($part))
{
return false;
}
}
return true;
}
return false;
}
$ip = '212.74.53.102';
echo $ip."<br>";
if(is_ip($ip) == true)
{
echo "It's an IP";
}
else
{
echo "I don't know that it is, but it sure isn't a valid IP";
}
?>