Re: about PHP's filter_var function
| From: | Sebastian Krebs | Date: | Thu, 20 Sep 2012 16:58:28 +0000 |
| Subject: | Re: about PHP's filter_var function | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-319161@lists.php.net to get a copy of this message | ||
Am 20.09.2012 18:03, schrieb Jim Lucas:
On 09/20/2012 02:35 AM, Sebastian Krebs wrote:No, negative numbers are "true" too. Only 0 is false, so '0.0.0.0' is the only edge case.Plaseplease update... 5.1.6 is from 2006! I read the "it's required", but I can't imagine _anything_ that it's worth it to use such an extremely outdated, unsupported and therefore insecure and inefficient version... You know: There are 3 (!) new minor versions available right now (5.2, 5.3 and 5.4). However: Regarding your concrete problem I guess you can use ip2long() if (ip2long($ip)) {I would suggest a modification to this. if ( ip2long($ip) !== false ) { I suggest this because IP to long will return negative numbers for half the IP range. Therefor 50% of your possible results would be considered false when in fact they are valid IPs. See Example #2 on this page: http://php.net/manual/en/function.ip2long.php
} else { } Regards, Sebastian Am 20.09.2012 11:14, schrieb lx:Hello: I want to use filter_var function by this way: $ip = "192.168.0.1"; if( !filter_var($ip, FILTER_VALIDATE_IP) ) { echo "IP is not valid"; } else { echo "IP is valid"; } I want to check the string $ip is IP address or not.but my PHP version is 5.1.6. and I know the filter_var requires at least PHP version 5.2.0. so, Any other function in PHP 5.1.6 can slove this work and replace the filter_var function ? Thank you, I'm a new one, so I don't know much about PHP documentation. By the way, The PHP version is required. so I can't upgrade it.