[Function] ip2long, long2ip
페이지 정보
작성자 MintState 댓글 0건 조회 14,471회 작성일 08-11-17 10:28본문
[Function] ip2long, long2ip
ip2long — Converts a string containing an (IPv4) Internet Protocol dotted address into a proper address
ex)
long2ip — Converts an (IPv4) Internet network address into a string in Internet standard dotted format
If the function doesn't exist:
$a = ip2long('192.168.0.4));
$b = long2ip($a);
echo $a . "_____________" . $b;
ip2long — Converts a string containing an (IPv4) Internet Protocol dotted address into a proper address
ex)
<?php
$ip = gethostbyname('www.example.com');
$long = ip2long($ip)
if ($long == -1 || $long === FALSE) {
echo 'Invalid IP, please try again';
} else {
$out = "The following URLs are equivalent:<br />\n";
$out .= 'http://www.example.com/, http://' . $ip . '/, and http://' . sprintf("%u", $long) . "/<br />\n";
echo $out;
}
?>
long2ip — Converts an (IPv4) Internet network address into a string in Internet standard dotted format
If the function doesn't exist:
<?
if (!function_exists("long2ip")) {
function long2ip($long) {
// Valid range: 0.0.0.0 -> 255.255.255.255
if ($long < 0 || $long > 4294967295) return false;
$ip = "";
for ($i=3;$i>=0;$i--) {
$ip .= (int)($long / pow(256,$i));
$long -= (int)($long / pow(256,$i))*pow(256,$i);
if ($i>0) $ip .= ".";
}
return $ip;
}
}
?>
$a = ip2long('192.168.0.4));
$b = long2ip($a);
echo $a . "_____________" . $b;
|
|
댓글목록
등록된 댓글이 없습니다.





[Function] ip2long, long2ip