note 112579 deleted from function.preg-match by cmb
| From: | cmb@php.net | Date: | Sun, 04 Dec 2016 12:06:18 +0000 |
| Subject: | note 112579 deleted from function.preg-match by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-208181@lists.php.net to get a copy of this message | ||
Note Submitter: hessemanj2100 at gmail dot com
----
The most accurate IPv4 function. It will not allow leading zeros and supports the full address range
of 0.0.0.0 - 255.255.255.255
<?php
function is_ipv4($string)
{
// The regular expression checks for any number between 0 and 255 beginning with a dot (repeated 3
times)
// followed by another number between 0 and 255 at the end. The equivalent to an IPv4 address.
return (bool) preg_match('/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])'.
'\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]?|[0-9])$/', $string);
}
?>