Removing information from a string

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.


This line returns 'Country: UNITED KINGDOM (GB) City: Edinburgh IP:' 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.

 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:

$jstring = file_get_contents(''.$ip);
$ipinfo = json_decode($jstring);

And this gives:

stdClass Object
    [country_name] => NETHERLANDS
    [country_code] => NL
    [city] => (Unknown city)
    [ip] => xx.xx.10.9

This can be used as:

echo $ipinfo->city;

Need Your Help

how can i read data from csv file and store in binary tree and write multiple file in perl

perl csv binary-tree

I have CSV file which have more than 10 lakh data. I want to use binary::tree for less memory uses.

Optimize multi-join query, please

mysql sql query-optimization average

i made a query for sql but it's really heavy and i really don't see how i can optimize it, the explanations comes after :