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

[Function] ip2long, long2ip

페이지 정보

작성자 MintState 댓글 0건 조회 13,788회 작성일 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건 2 페이지
PHP 목록
번호 제목 글쓴이 조회 날짜
140 MintState 18342 07-02
139 MintState 16340 06-30
138 MintState 22451 04-28
137 MintState 15910 02-12
136 MintState 28701 01-13
135 MintState 16463 10-09
134 MintState 18197 08-25
133 MintState 15235 07-28
132 MintState 18585 04-28
131 MintState 23539 04-09
130 MintState 16050 04-06
129 MintState 13354 02-25
128 MintState 16604 02-25
127 MintState 12345 02-23
126 MintState 11579 02-23
125 MintState 15998 02-23
124 MintState 16325 02-17
123 MintState 15313 02-17
122 MintState 16926 11-17
121 MintState 22247 11-17
120 MintState 12214 11-17
119 MintState 17182 11-17
열람중 MintState 13789 11-17
117 MintState 16129 11-10
116 MintState 14453 11-10
게시물 검색
모바일 버전으로 보기
CopyRight ©2004 - 2024, YesYo.com MintState. ™