ID: 21277 Updated by: [EMAIL PROTECTED] Reported By: [EMAIL PROTECTED] -Status: Open +Status: Won\'t fix Bug Type: Feature/Change Request Operating System: Linux PHP Version: 4.2.3 New Comment:
Can be done with a oneliner: (something along the lines of:) if (preg_match("/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\$/", $ip) { /* It is an IP */ } Not really worth the trouble to implement it as a PHP code feature. Derick Previous Comments: ------------------------------------------------------------------------ [2002-12-29 18:54:21] [EMAIL PROTECTED] function is_ip($str) // Returns True if the given string is a IP address { if ((substr_count($str, ".") != 3) or (empty($str))) { return false; } $ip_array = explode(".", $str); for ($i = 0; $i < count($ip_array); $i++) { if ((strlen($ip_array[$i]) != 3) or (!is_numeric($ip_array[$i]))) { return false; } } return true; } I think that this function could be useful for many PHP coders :) ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=21277&edit=1