HomeMenu
Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

ip2long

Description

The ip2long of Network for PHP converts a string containing an (IPv4) Internet Protocol dotted address into a long integer.

Syntax

ip2long(
    string $ip
): int|false

Parameters

ip

A standard format address.

Return

Returns the long integer or false if ip is invalid.

Examples

1 · ip

<?

$hostname = "php.net";

$ip = gethostbyname($hostname);

$return = ip2long($ip);

echo $hostname . PHP_EOL
. $ip . PHP_EOL
. $return;
php.net
185.85.0.29
3109355549

2 · 32-bit systems

<?

$hostname = "php.net";

$ip = gethostbyname($hostname);

$return = ip2long($ip);

if($return == -1 || $return === false)
{
    echo "invalid";
}
else
{
    echo sprintf("%u", $return);
}
3109355549