How to Get IP Address of Domain or URL via PHP

Learn how to retrieve a website IP address with PHP and use it later on. In my case I wanted it to update the DNS record.

This is a short tutorial on how to get your domain or URL via PHP. I was looking on a way how to retrieve the IP of the website for me to update a DNS record via Cloudflare.

$domain = "";

$ip = gethostbyname($domain);

echo "Domain: ".$domain;
echo "<br>";
echo "IP: ".$ip;