The Wayback Machine - https://web.archive.org/web/20230422235622/https://www.geeksforgeeks.org/php-gethostbyname-function/
Skip to content
Related Articles
Get the best out of our app
GFG App
Open App
geeksforgeeks
Browser
Continue

Related Articles

PHP | gethostbyname() Function

Improve Article
Save Article
Like Article
author
gekcho
proficient
149 published articles
Improve Article
Save Article
Like Article

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:




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

Output:

52.25.109.230

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

My Personal Notes arrow_drop_up
Last Updated : 29 Aug, 2019
Like Article
Save Article
Similar Reads
Related Tutorials