English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

PHP basic tutorial

PHP advanced tutorial

PHP & MySQL

PHP reference manual

PHP gethostbyname() function usage and example

PHP HTTP  reference manual

The gethostbyname() function returns the IPv4 address corresponding to the hostname.

Syntax

string gethostbyname ( string $hostname )

Definition and usage

 Returns the IPv4 internet address corresponding to the hostname hostname.

Return value

 Returns the IPv4 address when successful, and returns the hostname string unchanged when failed.

Parameter

ParameterDescription
hostnameIt gives the corresponding hostname

Example

Try the following example

<?php
$ip = gethostbyname('ru.oldtoolbag.com');
echo $ip;
echo $hostname;
?>

The above example shows the result of the w3codebox IPV4 address.

PHP HTTP  reference manual