cvs: phpdoc /en/functions network.xml

From: Date: Sat, 03 Nov 2001 18:47:13 +0000
Subject: cvs: phpdoc /en/functions network.xml
Groups: php.doc 
Request: Send a blank email to phpdoc+get-969338477@lists.php.net to get a copy of this message
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"> &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>

« previous php.doc (#969338477) next »