I'm using free API services to provide me informations about location of IPs and here is the code i'm using
$api = file_get_contents('http://api_site.com?ip=XX.XX.XX.XX');
// WHERE XX.XX.XX.XX Is IP and api_site.com is my provider
The output is as following (this is on me)
OK;XX.XX.XX.XX;EG;EGYPT;AL QAHIRAH;CAIRO;+02:00
// ok , IP , Country code , Country , Region , City , Time zone GMT
Now how to get the following output into array so i can easily show it up I've used the following code.
$api = file_get_contents('http://api_site.com?ip=XX.XX.XX.XX');
$info = array_shift(explode(";", api));
$message = "$info";
// Output is just "OK"
//OK;XX.XX.XX.XX;EG;EGYPT;AL QAHIRAH;CAIRO;+02:00
// I want get all sperated
so is there any way i can explode by ;
and get all and be able to show up ~ thanks
why are you using array_shift
? that function will return the first element of the array removing it from the array itself. This shoul be enough:
$api = file_get_contents('http://api_site.com?ip=XX.XX.XX.XX');
$info = explode(";", $api);
if you want to print out the results all together the you need to use implode
function, which has the same parameters as explode
You only need to explode. Don't use array_shift at all. Here's an example:
$info = explode(";", api);
$message = spritnf('Country: %s', $info[3]);