php函数long2ip与ip2long()

时间:2023-03-09 01:19:00
php函数long2ip与ip2long()

long2ip — Converts an long integer address into a string in (IPv4) Internet standard dotted format

string long2ip ( string $proper_address )

The function long2ip() generates an Internet address in dotted format (i.e.: aaa.bbb.ccc.ddd) from the long integer representation

意思就是:用于将一个数字格式的IPv4地址转换成字符串格式(192.168.0.1)

而ip2long恰好与之相反

Converts an long integer address into a string in (IPv4) Internet standard dotted format

eg:

<?php
$ip = gethostbyname('www.csdn.net');

        $num_ip =  ip2long($ip);
echo $num_ip,'<br/>';
echo long2ip($num_ip);

?>

结果:

php函数long2ip与ip2long()