note 71000 added to function.eregi
| From: | m at tthew dot org dot uk | Date: | Tue, 07 Nov 2006 22:47:16 +0000 |
| Subject: | note 71000 added to function.eregi | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-119488@lists.php.net to get a copy of this message | ||
This example checks for a valid IP address or CIDR notation address range. (Thanks Walo for just the
start I needed.)
The reg exp is too long to post in the code. It is:
^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}(/[0-9]{1,2}){0,1}$
(substitute for EXPR)
<?php
function checkValidIp($cidr) {
// Checks for a valid IP address or optionally a cidr notation range
// e.g. 1.2.3.4 or 1.2.3.0/24
if(!eregi("EXPR", $cidr)) {
$return = FALSE;
} else {
$return = TRUE;
}
if ( $return == TRUE ) {
$parts = explode("/", $cidr);
$ip = $parts[0];
$netmask = $parts[1];
$octets = explode(".", $ip);
foreach ( $octets AS $octet ) {
if ( $octet > 255 ) {
$return = FALSE;
}
}
if ( ( $netmask != "" ) && ( $netmask > 32 ) ) {
$return = FALSE;
}
}
return $return;
}
?>
----
Server IP: 66.207.199.35
Probable Submitter: 24.86.195.69
----
Manual Page -- http://www.php.net/manual/en/function.eregi.php
Edit -- https://master.php.net/note/edit/71000
Del: integrated -- https://master.php.net/note/delete/71000/integrated
Del: useless -- https://master.php.net/note/delete/71000/useless
Del: bad code -- https://master.php.net/note/delete/71000/bad+code
Del: spam -- https://master.php.net/note/delete/71000/spam
Del: non-english -- https://master.php.net/note/delete/71000/non-english
Del: in docs -- https://master.php.net/note/delete/71000/in+docs
Del: other reasons-- https://master.php.net/note/delete/71000
Reject -- https://master.php.net/note/reject/71000
Search -- https://master.php.net/manage/user-notes.php