php8.5
Home/ Manual/ network / functions/ gethostbyname

gethostbyname

PHP function Edit on GitHub ✎

(PHP 4, PHP 5, PHP 7, PHP 8)

Get the IPv4 address corresponding to a given Internet host name

Description

gethostbyname(string $hostname): string

Returns the IPv4 address of the Internet host specified by hostname.

Parameters

hostname

The host name.

Return Values

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

Examples

A simple gethostbyname() example

php
<?php
$ip = gethostbyname('www.example.com');

echo $ip;
?>

See Also

Source: reference/network/functions/gethostbyname.xml · from the official PHP manual (php/doc-en)