(PHP 4, PHP 5, PHP 7)
ip2long — �� IPV4 ���ַ���������Э��ת���ɳ���������
$ip_address
) : int���� ip2long() ���� IPV4 �����ַ�ij�����ʽ���ӱ������ַ��ʽ(���ַ���)ת���õ���
ip2long() �������������IP���й����� �Ķ� » http://publibn.boulder.ibm.com/doc_link/en_US/a_doc_lib/libs/commtrf2/inet_addr.htm ��ø�����Ϣ��
ip_address
һ������ʽ�ĵ�ַ��
����IP��ַת��������� �� FALSE
��� ip_address
����Ч�ġ�
�汾 | ˵�� |
---|---|
5.5.0 | Prior to this version, on Windows ip2long() would sometimes return a valid number even if passed a value which was not an (IPv4) Internet Protocol dotted address. |
5.2.10 | �ٴ�֮ǰ�İ汾, ip2long() ��ʱ�᷵�ؼ�ʹ�ⲻ��һ��IPV4�ı���ַ�����ֵ�ַ�� |
Example #1 ip2long() ����
<?php
$ip = gethostbyname('www.example.com');
$out = "The following URLs are equivalent:<br />\n";
$out .= 'http://www.example.com/, http://' . $ip . '/, and http://' . sprintf("%u", ip2long($ip)) . "/<br />\n";
echo $out;
?>
Example #2 ��ʾIP��ַ
�ڶ�������˵����ӡһ��ת����ĵ�ַʹ�� printf() ��PHP4��PHP5�Ĺ���:
<?php
$ip = gethostbyname('www.example.com');
$long = ip2long($ip);
if ($long == -1 || $long === FALSE) {
echo 'Invalid IP, please try again';
} else {
echo $ip . "\n"; // 192.0.34.166
echo $long . "\n"; // -1073732954
printf("%u\n", ip2long($ip)); // 3221234342
}
?>