jimw Sat Nov 3 13:47:13 2001 EDT
Modified files:
/phpdoc/en/functions network.xml
Log:
update ip2long to note need for using '%u' in a printf or sprintf to output unsigned
value.
Index: phpdoc/en/functions/network.xml
diff -u phpdoc/en/functions/network.xml:1.41 phpdoc/en/functions/network.xml:1.42
--- phpdoc/en/functions/network.xml:1.41 Fri Sep 21 18:47:45 2001
+++ phpdoc/en/functions/network.xml Sat Nov 3 13:47:13 2001
@@ -1,5 +1,5 @@
<?xml encoding="iso-8859-1"?>
-<!-- $Revision: 1.41 $ -->
+<!-- $Revision: 1.42 $ -->
<reference id="ref.network">
<title>Network Functions</title>
<titleabbrev>Network</titleabbrev>
@@ -510,29 +510,36 @@
network address from its Internet standard format (dotted string)
representation.
<example>
- <title><function>ip2long</function> Example</title>
- <programlisting role="php">
+ <title><function>ip2long</function> Example</title>
+ <programlisting role="php">
<?php
$ip = gethostbyname("www.php.net");
$out = "The following URLs are equivalent:<br>\n";
-$out .= "http://www.php.net/, http://".$ip."/, and
http://".ip2long($ip)."/<br>\n";
+$out .= "http://www.php.net/, http://".$ip."/, and
+http://".sprintf("%u",ip2long($ip))."/<br>\n";
echo $out;
?>
- </programlisting>
+ </programlisting>
</example>
+ <note>
+ <para>
+ Because PHP's integer type is signed, and many IP addresses will
+ result in negative integers, you need to use the "%u" formatter of
+ <function>sprintf</function> or <function>printf</function> to get
+ the string representation of the unsigned IP address.
+ </note>
</para>
<para>
This second example shows how to print a converted address with the
<function>printf</function> function :
<example>
- <title>IP address displaying</title>
- <programlisting role="php">
+ <title>Displaying an IP address</title>
+ <programlisting role="php">
<?php
$ip = gethostbyname("www.php.net");
-printf ("%u\n", ip2long ($ip));
+printf("%u\n", ip2long($ip));
echo $out;
?>
- </programlisting>
+ </programlisting>
</example>
</para>
<para>