update ip2long to note need for using '%u' in a printf or sprintf to output unsigned value.

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@61472 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
jim winstead 2001-11-03 18:47:13 +00:00
parent 5f0d7cdec2
commit c4d649bdd9

View file

@ -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 @@ if (!$fp) {
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">
&lt;?php
$ip = gethostbyname("www.php.net");
$out = "The following URLs are equivalent:&lt;br&gt;\n";
$out .= "http://www.php.net/, http://".$ip."/, and http://".ip2long($ip)."/&lt;br&gt;\n";
$out .= "http://www.php.net/, http://".$ip."/, and http://".sprintf("%u",ip2long($ip))."/&lt;br&gt;\n";
echo $out;
?&gt;
</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">
&lt;?php
$ip = gethostbyname("www.php.net");
printf ("%u\n", ip2long ($ip));
printf("%u\n", ip2long($ip));
echo $out;
?&gt;
</programlisting>
</programlisting>
</example>
</para>
<para>