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

[Function] ip2long, long2ip

페이지 정보

작성자 MintState 댓글 0건 조회 10,591회 작성일 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 15152 07-02
139 MintState 13247 06-30
138 MintState 19351 04-28
137 MintState 12771 02-12
136 MintState 21284 01-13
135 MintState 13136 10-09
134 MintState 15097 08-25
133 MintState 12121 07-28
132 MintState 14720 04-28
131 MintState 19196 04-09
130 MintState 12886 04-06
129 MintState 10460 02-25
128 MintState 13320 02-25
127 MintState 9572 02-23
126 MintState 8898 02-23
125 MintState 12733 02-23
124 MintState 13378 02-17
123 MintState 12151 02-17
122 MintState 13945 11-17
121 MintState 15010 11-17
120 MintState 9329 11-17
119 MintState 14065 11-17
열람중 MintState 10592 11-17
117 MintState 12816 11-10
116 MintState 11352 11-10
게시물 검색
모바일 버전으로 보기
CopyRight ©2004 - 2020, YesYo.com MintState. ™