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

[Function] ip2long, long2ip

페이지 정보

작성자 MintState 댓글 0건 조회 9,558회 작성일 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 14008 07-02
139 MintState 12133 06-30
138 MintState 18061 04-28
137 MintState 11627 02-12
136 MintState 19761 01-13
135 MintState 12041 10-09
134 MintState 13763 08-25
133 MintState 10970 07-28
132 MintState 13232 04-28
131 MintState 16912 04-09
130 MintState 11753 04-06
129 MintState 9383 02-25
128 MintState 12038 02-25
127 MintState 8552 02-23
126 MintState 7798 02-23
125 MintState 11621 02-23
124 MintState 12110 02-17
123 MintState 10950 02-17
122 MintState 12925 11-17
121 MintState 12804 11-17
120 MintState 8302 11-17
119 MintState 12964 11-17
열람중 MintState 9559 11-17
117 MintState 11256 11-10
116 MintState 10096 11-10
게시물 검색
모바일 버전으로 보기
CopyRight ©2004 - 2019, YesYo.com MintState. ™