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 IPv corresponding to the hostname4Address.

Syntax

string gethostbyname ( string $hostname )

Definition and Usage

 Returns the IPv corresponding to the hostname hostname4 Internet address.

Return value

 Returns IPv when successful4 Address, if failed, returns the hostname string unchanged.

Parameter

ParameterDescription
hostnameIt gives the corresponding hostname

Example

Try the following example

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

The above example gives w3codebox IPV4The result of the address.

PHP HTTP Reference Manual