PHP | ip2long() Function

PHP ip2long() Function


Hello folks! welcome back to a new edition of our tutorial on PHP. In this tutorial guide, we are going to be studying about the PHP ip2long() Function.

The built-in PHP ip2long() function is used to convert IPv4 address to long integer.

Syntax

Following below is the syntax to use this function -

int ip2long ( string $ip_address )


Parameter Details

Sr.NoParameters & Description
1

ip_address

It contains an IP address.


Return Value

This built-in function returns a long integer on success, else it displays a message as IP address is invalid.

Example

Try out the following example below -

<?php
   $ip = gethostbyname('www.webdesigntutorialz.com');
   $out = "The following URLs are equivalent:
   \n";
   
   $out .= 'http://www.webdesigntutorialz.com/, http://' . $ip . '/, 
      and http://' . sprintf("%u", ip2long($ip)) . "/
   \n";
   
   echo $out;
?>

Output

When the above code is executed, it will produce the following result below -

The following URLs are equivalent:
http://www.webdesigntutorialz.com/, http://72.21.91.8/, and http://1209359112/


Alright guys! This is where we are going to be rounding up for this tutorial post. In our next tutorial, we are going to be discussing about the PHP long2ip() Function.

Do feel free to ask your questions where necessary and we will attend to them as soon as possible. If this tutorial was helpful to you, you can use the share button to share this tutorial.

Do follow us on our various social media handles available and also subscribe to our newsletter to get our tutorial posts delivered directly to your emails.

Thanks for reading and bye for now.