PHP | ip2long() Function Last Updated : 12 Jul, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report The ip2long() function is an inbuilt function in PHP that converts IPv4 address (dotted IP address) into a long integer. Syntax: int ip2long( string $ip_address ) Parameters: This function accepts single parameter as mentioned above and described below: $ip_address: It is required parameter which specifies an IP address. Return Value: This function returns a long integer on success or FALSE on failure. Note: This function is available on PHP 4.0.0 and newer versions.This function will work with non-complete IP addresses. Below programs illustrate the ip2long() function in PHP: Program 1: PHP <?php // Store host name into variable $host="geeksforgeeks.org"; // Get IP address from hostname $ip = gethostbyname($host); echo "These three URLs are equivalent:<br>"; $out = "1. https://" . $host . "/<br>" . "2. https://" . $ip . "/<br>" . "3. https://" . sprintf("%u", ip2long($ip)) . "/"; echo $out; ?> Output: These three URLs are equivalent: 1. https://www.geeksforgeeks.org/ 2. https://52.25.109.230/ 3. https://874081766/ Program 2: PHP <?php // Store the list of hostname in an array $hosts = array( "geeksforgeeks.org", "www.google.com", "www.youtube.com", "www.facebook.com", "www.quora.com", "www.stackoverflow.com" ); $out = "Equivalent Contents:"; foreach( $hosts as $host ) { $ip = gethostbyname($host); $out .= "<br>https://" . $host . "/ https://" . $ip . "/ https://" . sprintf("%u", ip2long($ip)) . "/"; } echo $out; ?> Output: Equivalent Contents: https://www.geeksforgeeks.org/ https://52.25.109.230/ https://874081766/ https://www.google.com/ https://172.217.167.196/ https://2899945412/ https://www.youtube.com/ https://172.217.18.206/ https://2899907278/ https://www.facebook.com/ https://185.60.216.35/ https://3107772451/ https://www.quora.com/ https://151.101.1.2/ https://2539979010/ https://stackoverflow.com/questions https://151.101.1.69/ https://2539979077/ Reference: https://www.php.net/manual/en/function.ip2long.php Comment More infoAdvertise with us Next Article PHP | long2ip() Function G gekcho Follow Improve Article Tags : Web Technologies PHP PHP-function Similar Reads PHP is_long() Function The is_long() function is an inbuilt function in PHP that is used to check whether the given value is a long integer or not. Syntax: bool is_long(mixed $value) Parameters: This function accepts a single parameter $value that holds the value which needs to check for a long integer. Return Value: This 1 min read PHP | long2ip() Function The long2ip() function is an inbuilt function in PHP which converts long integer into corresponding IPv4 address in string format. Syntax: string long2ip( int $ip_in_long ) Parameters: This function accepts single parameter as mentioned above and described below: $ip_in_long: It is required paramete 1 min read PHP log1p() Function The log1p() is an inbuilt PHP function that returns log(1+number), & when the value of the number is close to zero, then it will compute the way that will provide the accurate result. Syntax: log1p(float $num): floatParameter: This function accepts only a single parameter: num: This parameter sp 1 min read PHP hypot() function The hypot() function is a built-in mathematical function in PHP and returns the square root of sum of square of arguments passed. It finds the hypotenuse, hypotenuse is the longest side of a right angled triangle. It is calculated by the formula : h = \sqrt{x^2+y^2} where x and y are the other two s 1 min read PHP | idate() Function The idate() function is an inbuilt function in PHP which is used to format a local time/date as an integer. The $format and $timestamp are sent as parameters to the idate() function and it returns an integer formatted according to the specified format using the given timestamp. Unlike the function d 2 min read PHP | inet_pton() Function The inet_pton() function is an inbuilt function in PHP which converts a readable format IP address into a packed 32bit IPv4 or 128bit IPv6 address. Syntax: string inet_pton( string $ip_address ) Parameters: This function accepts single parameter as mentioned above and described below: $ip_address: I 1 min read Like