PHP Function Reference

PHP long2ip() Function



The PHP long2ip() function converts long integer into corresponding IPv4 address in string format.

Syntax

long2ip(ip)

Parameters

ip Required. Specify a long integer that represents an IP address.

Return Value

Returns the Internet IP address as a string, or false on failure.

Example:

The example below shows the usage of long2ip() function.

<?php
echo long2ip(599805662);
?>

The output of the above code will be:

35.192.78.222

Example:

Consider one more example where this function is used with a number of long integers representing IP addresses.

<?php
$hosts=[599805662, 2915221899, 
        2398781531, 2649752099];

$out = "List of IP addresses:";
 
foreach($hosts as $host) {
  $ip = long2ip($host);
  $hostname = gethostbyaddr($ip);

  $out .= "\nhttps://". $host ."/  https://". $ip .
            "/  https://". $hostname ."/";
}
 
echo $out;
?>

The output of the above code will be:

List of IP addresses:
https://599805662/  https://35.192.78.222/  https://222.78.192.35.bc.googleusercontent.com/
https://2915221899/  https://173.194.193.139/  https://iu-in-f139.1e100.net/
https://2398781531/  https://142.250.128.91/  https://ib-in-f91.1e100.net/
https://2649752099/  https://157.240.2.35/  https://edge-star-mini-shv-01-ort2.facebook.com/

❮ PHP Network Reference

5