note 61986 deleted from function.preg-match-all by colder

From: Date: Mon, 16 Apr 2007 17:01:45 +0000
Subject: note 61986 deleted from function.preg-match-all by colder
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-125469@lists.php.net to get a copy of this message
Note Submitter: volkank at developera dot com ---- Correct IP matching Pattern: This is my new IP octet pattern seems to be correct: $num="(25[0-5]|2[0-4]\d|[01]?\d\d|\d)"; /* 25[0-5] => 250-255 2[0-4]\d => 200-249 [01]?\d\d => 00-99,000-199 \d => 0-9 */ GRABBING multiple Valid IP addresses from string <? $num="(25[0-5]|2[0-4]\d|[01]?\d\d|\d)"; $test="127.0.0.112 10.0.0.2"; preg_match_all("/$num\\.$num\\.$num\\.$num/",$test,$match); print_r($match); ?> Single IP validation <? $num="(25[0-5]|2[0-4]\d|[01]?\d\d|\d)"; $ip_addr='009.111.111.100'; if (!preg_match("/^$num\\.$num\\.$num\\.$num$/", $ip_addr,$match)) echo "Wrong IP Address\\n"; echo $match[0]; ?>

« previous php.notes (#125469) next »