Change language

PHP Ip2long () function

Syntax:
int ip2long (string $ip_address)
Parameters:This function takes one parameter as above and described below:
  • $ip_address:Required parameter that specifies the IP address.
Return Value:This function returns a long integer on success or FALSE on error.Notes:
  • This function is available in PHP 4.0.0 and above.
  • This function will work with incomplete IP addresses.
The programs below illustrate the ip2long() function in PHP:Program 1:  
// Save the hostname to a variable $host = "engineerforengineer.org" ;  
// Get an IP address from the host $ip = gethostbyname ( $host ); echo " These three URLs are equivalent:
"
; $out = " 1. https:// " . $host . "/
"
. "2. https:// " . $ip . "/
"
. "3. https:// " . sprintf ( "% u" , ip2long ( $ip )). "/" ; echo $out ;  
?>
Output:
These three URLs are equivalent: 1.https://engineerforengineer.org/ 2.https://52.25.109.230/ 3.https://874081766 /
Program 2 :  
// Store hostname list in arry $hosts = array ( "engineerforengineer.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 . = "
https:// "
. $host . "/  https://" . $ip . "/  https:// " . sprintf ( "% u" , ip2long ( $ip )). "/" ; } echo $out ;  
?>
Output:
Equivalent Contents: https://engineerforengineer.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://www.stackoverflow.com/ https://151.101.1.69/ https://2539979077 /
Link: https://www .php.net / manual / en / function.ip2long.php

Shop

Best laptop for Sims 4

$

Best laptop for Zoom

$499

Best laptop for Minecraft

$590

Best laptop for engineering student

$

Best laptop for development

$

Best laptop for Cricut Maker

$

Best laptop for hacking

$890

Best laptop for Machine Learning

$950

Latest questions

NUMPYNUMPY

psycopg2: insert multiple rows with one query

12 answers

NUMPYNUMPY

How to convert Nonetype to int or string?

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Javascript Error: IPython is not defined in JupyterLab

12 answers

Wiki

Python OpenCV | cv2.putText () method

numpy.arctan2 () in Python

Python | os.path.realpath () method

Python OpenCV | cv2.circle () method

Python OpenCV cv2.cvtColor () method

Python - Move item to the end of the list

time.perf_counter () function in Python

Check if one list is a subset of another in Python

Python os.path.join () method