PHP | gethostbyname() Function

The gethostbyname() function is an inbuilt function in PHP which returns IPv4 address for a specified host/domain name.

Syntax:

string gethostbyname( $hostname )

Parameter: This function accepts single parameter $hostname which is required. It specifies the hostname whose IPv4 address to be found.



Return Value: This function returns the IPv4 address on success or string containing the unmodified hostname on failure.

Note: This function is available for PHP 4.0.0 and newer versions.

Below program illustrates the gethostbyname() function in PHP:

Program:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
$ip = gethostbyname("geeksforgeeks.org");
  
echo $ip;
?>

chevron_right


Output:

52.25.109.230

Reference: https://www.php.net/manual/en/function.gethostbyname.php



My Personal Notes arrow_drop_up

I am unrecognized crazy being with random thoughts

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.