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

[Function] ip2long, long2ip

페이지 정보

작성자 MintState 댓글 0건 조회 14,106회 작성일 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 18649 07-02
139 MintState 16639 06-30
138 MintState 22786 04-28
137 MintState 16253 02-12
136 MintState 28991 01-13
135 MintState 16779 10-09
134 MintState 18505 08-25
133 MintState 15597 07-28
132 MintState 18946 04-28
131 MintState 23898 04-09
130 MintState 16380 04-06
129 MintState 13674 02-25
128 MintState 16923 02-25
127 MintState 12656 02-23
126 MintState 11873 02-23
125 MintState 16320 02-23
124 MintState 16664 02-17
123 MintState 15629 02-17
122 MintState 17246 11-17
121 MintState 22612 11-17
120 MintState 12510 11-17
119 MintState 17516 11-17
열람중 MintState 14107 11-17
117 MintState 16576 11-10
116 MintState 14755 11-10
게시물 검색
모바일 버전으로 보기
CopyRight ©2004 - 2024, YesYo.com MintState. ™