For the "dig" solution, here is a better one:
<?php
$IP = `/usr/bin/dig $host. A +short | /usr/bin/tail -n1`
?>
Using tail because dig, even in the +short form, may return CNAME entries first, and also may return many, many entries (see "dig google.com").
Usig the dot at the end of the host to not perform domain searches.
This works also when $host = IP address already
Will return empty string in case o resolve failure (invalid hostname)