When doing large subtractions on 32 bit unsigned integers the result sometimes end up negative. My example script converts a IPv4 address represented as a 32 bit unsigned integer to a dotted quad (similar to ip2long()), and adds a "fix" to the operation.
/**************************
* int_oct($ip)
* Convert INTeger rep of IP to octal (dotted quad)
*/
function int_oct($ip) {
/* Set variable to float */
settype($ip, float);
/* FIX for silly PHP integer syndrome */
$fix = 0;
if($ip > 2147483647) $fix = 16777216;
if(is_numeric($ip)) {
return(sprintf("%u.%u.%u.%u",
$ip / 16777216,
(($ip % 16777216) + $fix) / 65536,
(($ip % 65536) + $fix / 256) / 256,
($ip % 256) + $fix / 256 / 256
)
);
}
else {
return('');
}
}