I’m using an API which uses the users IP address to find out the users Country Location and City, however I have never used regex before and I have no Idea how to extract the other information I want.
$location=file_get_contents('http://api.hostip.info/get_html.php?ip='.$ip);
This line returns ‘Country: UNITED KINGDOM (GB) City: Edinburgh IP: 80.192.82.75‘ I have managed to extract the IP address using regex, but have no idea how to remove the Country and City into separate variables ($country = , $city =). Here is the code below I have so far.
$ip=$_SERVER['REMOTE_ADDR'];
$location=file_get_contents('http://api.hostip.info/get_html.php?ip='.$ip);
preg_match("/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/", $location, $matches);
$ip = $matches[0];
Taking the suggestion from millimoose it would look like this:
And this gives:
This can be used as: