reference/network/functions/ip2long.xml
184f3f7bd45643cb80f828d0bb001991ec3a5fad
...
...
@@ -1,21 +1,21 @@
1
1
<?xml version="1.0" encoding="utf-8"?>
2
2
<!-- $Revision$ -->
3
-
<refentry xml:id="function.ip2long" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
3
+
<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="function.ip2long">
4
4
<refnamediv>
5
5
<refname>ip2long</refname>
6
-
<refpurpose>Converts a string containing an (IPv4) Internet Protocol dotted address into a proper address</refpurpose>
6
+
<refpurpose>Converts a string containing an (IPv4) Internet Protocol dotted address into a long integer</refpurpose>
7
7
</refnamediv>
8
8
9
9
<refsect1 role="description">
10
10
&reftitle.description;
11
11
<methodsynopsis>
12
-
<type>int</type><methodname>ip2long</methodname>
13
-
<methodparam><type>string</type><parameter>ip_address</parameter></methodparam>
12
+
<type class="union"><type>int</type><type>false</type></type><methodname>ip2long</methodname>
13
+
<methodparam><type>string</type><parameter>ip</parameter></methodparam>
14
14
</methodsynopsis>
15
15
<para>
16
-
The function <function>ip2long</function> generates an IPv4 Internet
17
-
network address from its Internet standard format (dotted string)
18
-
representation.
16
+
The function <function>ip2long</function> generates a long integer
17
+
representation of IPv4 Internet network address from its Internet
18
+
standard format (dotted string) representation.
19
19
</para>
20
20
<para>
21
21
<function>ip2long</function> will also work with non-complete IP
...
...
@@ -29,7 +29,7 @@
29
29
<para>
30
30
<variablelist>
31
31
<varlistentry>
32
-
<term><parameter>ip_address</parameter></term>
32
+
<term><parameter>ip</parameter></term>
33
33
<listitem>
34
34
<para>
35
35
A standard format address.
...
...
@@ -43,37 +43,11 @@
43
43
<refsect1 role="returnvalues">
44
44
&reftitle.returnvalues;
45
45
<para>
46
-
Returns the IPv4 address or &false; if <parameter>ip_address</parameter>
46
+
Returns the long integer or &false; if <parameter>ip</parameter>
47
47
is invalid.
48
48
</para>
49
49
</refsect1>
50
50

51
-
<refsect1 role="changelog">
52
-
&reftitle.changelog;
53
-
<para>
54
-
<informaltable>
55
-
<tgroup cols="2">
56
-
<thead>
57
-
<row>
58
-
<entry>&Version;</entry>
59
-
<entry>&Description;</entry>
60
-
</row>
61
-
</thead>
62
-
<tbody>
63
-
<row>
64
-
<entry>5.2.10</entry>
65
-
<entry>
66
-
Prior to this version, <function>ip2long</function> would sometimes return
67
-
a valid number even if passed an value which was not an (IPv4) Internet Protocol
68
-
dotted address.
69
-
</entry>
70
-
</row>
71
-
</tbody>
72
-
</tgroup>
73
-
</informaltable>
74
-
</para>
75
-
</refsect1>
76
-

77
51
<refsect1 role="examples">
78
52
&reftitle.examples;
79
53
<para>
...
...
@@ -96,7 +70,7 @@ echo $out;
96
70
<title>Displaying an IP address</title>
97
71
<para>
98
72
This second example shows how to print a converted address with the
99
-
<function>printf</function> function in both PHP 4 and PHP 5:
73
+
<function>printf</function> function:
100
74
</para>
101
75
<programlisting role="php">
102
76
<![CDATA[
...
...
@@ -107,8 +81,8 @@ $long = ip2long($ip);
107
81
if ($long == -1 || $long === FALSE) {
108
82
echo 'Invalid IP, please try again';
109
83
} else {
110
-
echo $ip . "\n"; // 192.0.34.166
111
-
echo $long . "\n"; // -1073732954
84
+
echo $ip . "\n"; // 192.0.34.166
85
+
echo $long . "\n"; // 3221234342 (-1073732954 on 32-bit systems, due to integer overflow)
112
86
printf("%u\n", ip2long($ip)); // 3221234342
113
87
}
114
88
?>
...
...
@@ -122,7 +96,7 @@ if ($long == -1 || $long === FALSE) {
122
96
&reftitle.notes;
123
97
<note>
124
98
<para>
125
-
Because PHP's <type>integer</type> type is signed, and many IP addresses
99
+
Because PHP's <type>int</type> type is signed, and many IP addresses
126
100
will result in negative integers on 32-bit architectures, you need to use
127
101
the "%u" formatter of <function>sprintf</function> or
128
102
<function>printf</function> to get the string representation of the
...
...
@@ -131,9 +105,8 @@ if ($long == -1 || $long === FALSE) {
131
105
</note>
132
106
<note>
133
107
<para>
134
-
<function>ip2long</function> will return &false; for the IP
135
-
<literal>255.255.255.255</literal> in PHP 5 &lt;= 5.0.2. It was fixed in
136
-
PHP 5.0.3 where it returns <literal>-1</literal> (same as PHP 4).
108
+
<function>ip2long</function> will return <literal>-1</literal> for the IP
109
+
<literal>255.255.255.255</literal> on 32-bit systems due to the integer value overflowing.
137
110
</para>
138
111
</note>
139
112
</refsect1>
...
...
@@ -149,7 +122,6 @@ if ($long == -1 || $long === FALSE) {
149
122
</refsect1>
150
123

151
124
</refentry>
152
-

153
125
<!-- Keep this comment at the end of the file
154
126
Local variables:
155
127
mode: sgml
156
128