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; ?> - +