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

[Function] ip2long, long2ip

페이지 정보

작성자 MintState 댓글 0건 조회 14,094회 작성일 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 18630 07-02
139 MintState 16624 06-30
138 MintState 22767 04-28
137 MintState 16238 02-12
136 MintState 28970 01-13
135 MintState 16764 10-09
134 MintState 18491 08-25
133 MintState 15581 07-28
132 MintState 18927 04-28
131 MintState 23854 04-09
130 MintState 16365 04-06
129 MintState 13657 02-25
128 MintState 16908 02-25
127 MintState 12641 02-23
126 MintState 11856 02-23
125 MintState 16305 02-23
124 MintState 16649 02-17
123 MintState 15614 02-17
122 MintState 17229 11-17
121 MintState 22590 11-17
120 MintState 12493 11-17
119 MintState 17500 11-17
열람중 MintState 14095 11-17
117 MintState 16560 11-10
116 MintState 14741 11-10
게시물 검색
모바일 버전으로 보기
CopyRight ©2004 - 2024, YesYo.com MintState. ™