Skip to content
PHP Logo

What PHP function can be used to resolve a domain to an IP address?

To resolve a domain to an IP address in PHP, you can use the `gethostbyname()` function. This function takes a domain name as input and returns the corresponding IP address. It can be useful when you need to work with IP addresses instead of domain names in your PHP code.

php
$domain = "example.com";
$ip_address = gethostbyname($domain);
echo "The IP address of $domain is: $ip_address";