note 119272 deleted from function.is-numeric by cmb
| From: | cmb@php.net | Date: | Tue, 24 May 2016 13:49:01 +0000 |
| Subject: | note 119272 deleted from function.is-numeric by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-205574@lists.php.net to get a copy of this message | ||
Note Submitter: root at pspider dot com
----
Hey everyone! I have brought a handy function which checks if the input is an IP address. I posted
here because it is a numeric string, and uses function is_numeric();
<?php
/*
is_ipaddress($input)
*/
function is_ipaddress($input) {
$ctra = 0;
$tmpout = explode(".",$input);
if (count($tmpout) == 4) {
// There are four sections in the array (Ex. XXX.XXX.XXX.XXX)
// Check if all elements of array are a number (Ex. 127.0.0.1)
foreach ($element in $tmpout) {
if (is_numeric($element)) {
// The element is numeric.
++$ctra;
}
}
// Is the count of numeric elements = 4 ?
if ($ctra == 4) {
return true;
}
else {
return false;
}
}
else {
return false;
}
}
?>
If you can condense this further, please let me know @ my email address I have posted under. Thanks!
nJoy~!!!