note 119334 deleted from function.is-numeric by cmb

From: Date: Tue, 24 May 2016 13:49:09 +0000
Subject: note 119334 deleted from function.is-numeric by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-205575@lists.php.net to get a copy of this message
Note Submitter: root at pspider dot com ---- 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 ;)

« previous php.notes (#205575) next »