Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get IP from "http://" or "www" in PHP?

Tags:

php

curl

How do I get something in PHP/Curl to grab the IP of the URL for me? It's going to be a simple interface that fetches URL IP's back for me.

E.g. Enter "http://mysite.com" then I hit submit then I should get the IP of the mysite.com back.

like image 894
Ray Avatar asked Dec 04 '22 11:12

Ray


2 Answers

gethostbyname

$ip_string = gethostbyname( "stackoverflow.com" );
echo $ip_string; //returns ip address, ie 12.34.56.78
like image 162
Kendall Hopkins Avatar answered Dec 06 '22 01:12

Kendall Hopkins


Try the gethostbyname function.

like image 21
Stoosh Avatar answered Dec 06 '22 00:12

Stoosh