PHP Function Reference

PHP gethostbyname() Function



The PHP gethostbyname() function returns the IPv4 address for a given domain/host name. The function returns a string containing the unmodified hostname on failure.

Syntax

gethostbyname(hostname)

Parameters

hostname Required. Specify the host name.

Return Value

Returns the IPv4 address or a string containing the unmodified hostname on failure.

Example:

The example below shows the usage of gethostbyname() function.

<?php
$ip = gethostbyname('www.alphacodingskills.com');
print_r($ip);
?>

The output of the above code will be:

34.66.60.131

❮ PHP Network Reference

5