Example 1 — List Every IPv4 Address
Resolve a host and print each address on its own line. Sample output shows one typical address.
<?php
$ips = gethostbynamel("example.com");
if ($ips === false) {
echo "lookup failed", PHP_EOL;
} else {
foreach ($ips as $ip) {
echo $ip, PHP_EOL;
}
} How It Works
- gethostbynamel() returns array|false.
- We handle false before looping.
- Each array item is an IPv4 string.
- The printed IP is a typical sample for example. com.

