mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-16 00:48:54 +00:00
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:
parent
5f0d7cdec2
commit
c4d649bdd9
1 changed files with 16 additions and 9 deletions
|
@ -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">
|
||||
<?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>
|
||||
|
|
Loading…
Reference in a new issue