note 20116 deleted from function.is-numeric by nlopess
| From: | nlopess@php.net | Date: | Sat, 24 Sep 2005 07:52:55 +0000 |
| Subject: | note 20116 deleted from function.is-numeric by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-95689@lists.php.net to get a copy of this message | ||
Note Submitter: purecynergy at hotmail dot com
----
I made this function to check IP's so not to get the a.b.c format warning in the
gethostbyaddr() function PHP4.
It's basic but solved the is_numeric() multi-[.] problem.
<?php
function is_ip($ip) {
$valid = true;
$ip = explode(".", $ip);
foreach($ip as $block) {
if(!is_numeric($block)) {
$valid = false;
}
}
return $valid;
}
?>
returns true if the string does not contain anything outside the is_numeric() restraints else
returns false.
NOTE: this does't validate for full ip's only for the elements. That could be added easily
however.
ENJOY!