Changeset 207 for branches/awmn/globals/functions.php
- Timestamp:
- 10/03/2009 02:39:59 PM (3 years ago)
- File:
-
- 1 edited
-
branches/awmn/globals/functions.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/awmn/globals/functions.php
r203 r207 237 237 } 238 238 239 function correct_ip($ip, $ret_null=TRUE) {240 if ($ip == '' && $ret_null === TRUE) return '';239 function ip_to_ranges($ip, $ret_null=TRUE) { 240 if ($ip == '' && $ret_null === TRUE) return array(); 241 241 $t = explode(".", $ip, 4); 242 for ($i=0;$i<4;$i++) { 243 $t[$i] = (integer)($t[$i]); 244 } 245 return implode(".", $t); 246 } 247 248 function correct_ip_min($ip, $ret_null=TRUE, $pad=3) { 249 if ($ip == '' && $ret_null === TRUE) return ''; 250 $t = explode(".", $ip, 4); 251 for ($i=0;$i<4;$i++) { 252 if(!isset($t[$i+1]) && $t[$i] != null) { 253 switch (substr($t[$i], 0, 1)) { 254 case '0': 255 break; 256 case '1': 257 case '2': 258 $t[$i] = intval(str_pad($t[$i], (substr($t[$i], 1, 1) >= 6?2:$pad), "0")); 259 break; 260 default: 261 $t[$i] = intval(str_pad($t[$i], ($pad==3?2:$pad), "0")); 262 } 263 }elseif($t[$i] == null) { 264 $t[$i] = 0; 265 }else{ 266 $t[$i] = (integer)($t[$i]); 267 } 268 } 269 return implode(".", $t); 270 } 271 272 function correct_ip_max($ip, $ret_null=TRUE, $pad=3) { 273 if ($ip == '' && $ret_null === TRUE) return ''; 274 $t = explode(".", $ip, 4); 275 for ($i=0;$i<4;$i++) { 276 if(!isset($t[$i+1]) && $t[$i] != null) { 277 switch (substr($t[$i], 0, 1)) { 278 case '0': 279 break; 280 case '1': 281 case '2': 282 $t[$i] = intval(str_pad($t[$i], (substr($t[$i], 1, 1) >= 6?2:$pad), "9")); 283 break; 284 default: 285 $t[$i] = intval(str_pad($t[$i], ($pad==3?2:$pad), "9")); 286 } 287 if ($t[$i] > 255) $t[$i] = 255; 288 }elseif($t[$i] == null) { 289 $t[$i] = 255; 290 }else{ 291 $t[$i] = (integer)($t[$i]); 292 } 293 } 294 return implode(".", $t); 242 for ($i=0;$i<=3;$i++) { 243 if (isset($t[$i]) && $t[$i] != '' && $i != 3) $t[$i] = $t1[$i] = $t2[$i] = (integer)($t[$i]); 244 else { 245 $t1[$i] = 0; 246 $t2[$i] = 255; 247 } 248 } 249 $ret[] = array("min" => implode(".", $t1), "max" => implode(".", $t2)); 250 $p = count($t) - 1; 251 if ($p <= 2 && $t[$p] != 0) { 252 $d = 2 - intval(log10($t[$p])); 253 for ($i=1;$i<=$d;$i++) { 254 $t1[$p] = $t[$p] * pow(10,$i); 255 $t2[$p] = $t1[$p] + pow(10,$i) - 1; 256 if ($t2[$p] > 255) $t2[$p] = 255; 257 $ret[] = array("min" => implode(".", $t1), "max" => implode(".", $t2)); 258 } 259 } 260 return $ret; 295 261 } 296 262
Note: See TracChangeset
for help on using the changeset viewer.
