note 86587 added to function.substr

From: Date: Fri, 24 Oct 2008 21:31:36 +0000
Subject: note 86587 added to function.substr
Groups: php.notes 
Request: Send a blank email to php-notes+get-145722@lists.php.net to get a copy of this message
Here we have gr8 function which simply convert ip address to a number using substr with negative offset. You can need it if you want to compare some IP addresses converted to a numbers. For example when using ip2country, or eliminating same rang of ip addresses from your website :D <? function ip2no($val) { list($A,$B,$C,$D) = explode(".",$val); return substr("000".$A,-3). substr("000".$B,-3). substr("000".$C,-3). substr("000".$D,-3); } $min = ip2no("10.11.1.0"); $max = ip2no("111.11.1.0"); $visitor = ip2no("105.1.20.200"); if($min<$visitor && $visitor<$max) { echo 'Welcome !'; } else { echo 'Get out of here !'; } ?> ---- Server IP: 82.177.164.100 Probable Submitter: 80.55.196.98 ---- Manual Page -- http://www.php.net/manual/en/function.substr.php Edit -- https://master.php.net/note/edit/86587 Del: integrated -- https://master.php.net/note/delete/86587/integrated Del: useless -- https://master.php.net/note/delete/86587/useless Del: bad code -- https://master.php.net/note/delete/86587/bad+code Del: spam -- https://master.php.net/note/delete/86587/spam Del: non-english -- https://master.php.net/note/delete/86587/non-english Del: in docs -- https://master.php.net/note/delete/86587/in+docs Del: other reasons-- https://master.php.net/note/delete/86587 Reject -- https://master.php.net/note/reject/86587 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#145722) next »