From c4d649bdd9b6d20a760092ca2c5f8f3017034e35 Mon Sep 17 00:00:00 2001 From: jim winstead Date: Sat, 3 Nov 2001 18:47:13 +0000 Subject: [PATCH] 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 --- functions/network.xml | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/functions/network.xml b/functions/network.xml index 3afa11b5da..9a74f2e6bf 100644 --- a/functions/network.xml +++ b/functions/network.xml @@ -1,5 +1,5 @@ - + Network Functions Network @@ -510,29 +510,36 @@ if (!$fp) { network address from its Internet standard format (dotted string) representation. - <function>ip2long</function> Example - + <function>ip2long</function> Example + <?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; ?> - + + + + Because PHP's integer type is signed, and many IP addresses will + result in negative integers, you need to use the "%u" formatter of + sprintf or printf to get + the string representation of the unsigned IP address. + This second example shows how to print a converted address with the printf function : - IP address displaying - + Displaying an IP address + <?php $ip = gethostbyname("www.php.net"); -printf ("%u\n", ip2long ($ip)); +printf("%u\n", ip2long($ip)); echo $out; ?> - +