note 119334 added to function.is-numeric
| From: | root at pspider dot com | Date: | Sat, 14 May 2016 23:48:05 +0000 |
| Subject: | note 119334 added to function.is-numeric | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-205487@lists.php.net to get a copy of this message | ||
I realized my is_ipaddress function had a small bug. It would return true for an IP like
"1234.12345.123456.12345678" so I changed one if condition to ensure the length of each
group of numbers is less than or equal to 3.
NOTE: This function does not determine if the IP is restricted for LAN or other. In other words, it
will match 127.0.0.1
/*
is_ipaddress($input)
*/
function is_ipaddress($input) {
// PSpider.com -- My MOST genius function. 2016/04/29 @ 2131 EST
// Updated: 2016/05/14 @ 1946 EST
(stoned out of mind. slightly intoxicated)
// Added to PHP.NET manual under function is_numeric() - root@pspider.com
$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 as $tmpout) { // Nother noob steak....
if (is_numeric($element) && (strlen(($element) <= 3)) {
// The element is numeric.
++$ctra;
}
}
// Is the count of numeric elements = 4 and each element has 3 numbers ?
if ($ctra == 4) {
return true;
}
else {
return false;
}
}
else {
return false;
}
}
~nJoy ;)
----
Server IP: 72.52.91.14
Probable Submitter: 45.78.200.221
----
Manual Page -- http://php.net/manual/en/function.is-numeric.php
Edit -- https://master.php.net/note/edit/119334
Del: integrated -- https://master.php.net/note/delete/119334/integrated
Del: useless -- https://master.php.net/note/delete/119334/useless
Del: bad code -- https://master.php.net/note/delete/119334/bad+code
Del: spam -- https://master.php.net/note/delete/119334/spam
Del: non-english -- https://master.php.net/note/delete/119334/non-english
Del: in docs -- https://master.php.net/note/delete/119334/in+docs
Del: other reasons-- https://master.php.net/note/delete/119334
Reject -- https://master.php.net/note/reject/119334
Search -- https://master.php.net/manage/user-notes.php