YesYo.com MintState Forums
뒤로    YesYo.com MintState BBS > Tech > PHP
검색
멤버이름    오토
비밀번호 
 

[Function] ip2long, long2ip

페이지 정보

작성자 MintState 댓글 0건 조회 13,878회 작성일 08-11-17 10:28

본문

[Function] ip2long, long2ip

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;

댓글목록

등록된 댓글이 없습니다.

Total 165건 4 페이지
PHP 목록
번호 제목 글쓴이 조회 날짜
90 MintState 14448 11-03
89 MintState 14425 10-31
88 MintState 14396 11-03
87 MintState 14384 11-03
86 MintState 14373 11-03
85 MintState 14339 11-03
84 MintState 14312 11-10
83 MintState 13942 02-10
열람중 MintState 13879 11-17
81 MintState 13751 11-03
80 MintState 13731 10-31
79 MintState 13610 10-29
78 MintState 13589 11-03
77 MintState 13537 11-03
76 MintState 13500 11-03
75 MintState 13440 02-25
74 MintState 13439 10-29
73 MintState 13417 10-28
72 MintState 13398 11-03
71 MintState 13338 10-21
70 MintState 13315 10-31
69 MintState 13310 11-10
68 MintState 13219 02-26
67 MintState 13175 11-03
66 MintState 13050 10-28
게시물 검색
모바일 버전으로 보기
CopyRight ©2004 - 2024, YesYo.com MintState. ™