Deprecated: The each() function is deprecated. This message will be suppressed on further calls in /home/zhenxiangba/zhenxiangba.com/public_html/phproxy-improved-master/index.php on line 456
PHP: inet_pton - Manual
[go: Go Back, main page]

PHP
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

ip2long" width="11" height="7"/> <inet_ntop
Last updated: Thu, 03 May 2007

view this page in

inet_pton

(PHP 5 >= 5.1.0)

inet_pton — 人間が読める形式の IP アドレスを、パックされた形式に変換する

説明

string inet_pton ( string $address )

この関数は、人間が読める形式の IPv4 あるいは IPv6 (PHP が IPv6 サポートを有効にしてビルドされている場合)のアドレスを 32 ビットあるいは 128 ビットのバイナリ形式に変換します。

例 1545. inet_pton() の例

<?php
$in_addr
= inet_pton('127.0.0.1');

$in6_addr = inet_pton('::1');

?>

注意: この関数は Windows 環境にはまだ実装されていません。

ip2long()inet_ntop()、 および long2ip() も参照ください。



add a note add a note User Contributed Notes
inet_pton
me at diogoresende dot net
17-May-2006 06:34
If you want to use the above function you should test for ':' character before '.'. Meaning, you should check if it's an ipv6 address before checking for ipv4.
Why? IPv6 allows this type of notation:

::127.0.0.1

If you check for '.' character you will think this is an ipv4 address and it will fail.
djmaze(AT)dragonflycms(.)org
14-Dec-2005 05:01
If you need the functionality but your PHP version doesn't have the functionality (like on windows) the following might help

<?php
function inet_pton($ip)
{
   
# ipv4
   
if (strpos($ip, '.') !== FALSE) {
       
$ip = pack('N',ip2long($ip));
    }
   
# ipv6
   
elseif (strpos($ip, ':') !== FALSE) {
       
$ip = explode(':', $ip);
       
$res = str_pad('', (4*(8-count($ip))), '0000', STR_PAD_LEFT);
        foreach (
$ip as $seg) {
           
$res .= str_pad($seg, 4, '0', STR_PAD_LEFT);
        }
       
$ip = pack('H'.strlen($res), $res);
    }
    return
$ip;
}
?>

ip2long" width="11" height="7"/> <inet_ntop
Last updated: Thu, 03 May 2007
 
 
show source | credits | sitemap | contact | advertising | mirror sites