I've been searching for a while but I couldn't find a correct way to solve my problem.
Above all I try to sort out my problem following these two answers:
How to use cURL to get jSON data and decode the data?
and
How to parse out variables from a JSON var_dump in a Wordpress Plugin
but they didn't solve my problem.
So, this is my issue: I got this api:
and I can use only CURL library or fsockopen to retrieve the data.
I'm trying to use the CURL library on this way:
<?php
$url = 'http://data.aishub.net/ws.php?username=xxxxxxxxxx&format=1&output=json&compress=0&latmin=38.7&latmax=39&lonmin=9.3&lonmax=9.4';
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL,$url);
$result=curl_exec($ch);
curl_close($ch);
var_dump(json_decode($result, true));
$array[0][1][0]["MMSI"];
echo $array;
?>
and I get this answer:
array(2) { [0]=> array(8) { ["ERROR"]=> bool(false) ["USERNAME"]=> string(16) "xxxxxxxxxx"
["FORMAT"]=> string(5) "HUMAN" ["LATITUDE_MIN"]=> float(38.5) ["LATITUDE_MAX"]=> int(39)
["LONGITUDE_MIN"]=> float(9.3) ["LONGITUDE_MAX"]=> float(9.5) ["RECORDS"]=> int(2) } [1]=> array(2)
{ [0]=> array(19) { ["MMSI"]=> int(636012570) ["TIME"]=> string(23) "2015-05-24 15:58:13 GMT"
["LONGITUDE"]=> float(9.32533) ["LATITUDE"]=> float(38.79291) ["COG"]=> float(145.6) ["SOG"]=>
float(13.7) ["HEADING"]=> int(511) ["NAVSTAT"]=> int(0) ["IMO"]=> int(9144794) ["NAME"]=>
string(9) "CE NIRIIS" ["CALLSIGN"]=> string(5) "A8GG6" ["TYPE"]=> int(81) ["A"]=> int(205) ["B"]
=> int(38) ["C"]=> int(24) ["D"]=> int(18) ["DRAUGHT"]=> int(8) ["DEST"]=> string(18) "LA SKHIRRA TUNISIA"
["ETA"]=> string(11) "05-26 02:00" } [1]=> array(19) { ["MMSI"]=> int(247325500) ["TIME"]=>
string(23) "2015-05-24 15:56:22 GMT" ["LONGITUDE"]=> float(9.4617) ["LATITUDE"]=> float(38.89681)
["COG"]=> float(123.2) ["SOG"]=> float(10.5) ["HEADING"]=> int(120) ["NAVSTAT"]=> int(0)
["IMO"]=> int(9346902) ["NAME"]=> string(9) "SYN TABIT" ["CALLSIGN"]=> string(4) "IBEK"
["TYPE"]=> int(1) ["A"]=> int(72) ["B"]=> int(23) ["C"]=> int(11) ["D"]=> int(4) ["DRAUGHT"]=>
float(6.4) ["DEST"]=> string(12) "THESSALONICO" ["ETA"]=> string(11) "05-28 17:00" } } }
In this format:
array(2){[0]{part a}[1]{[0]{PART A}[1]{PART B}}}
I don't need retrieve the data on the "part a", but I need to work on PART A and PART B.
My intention is to search a value (ship name) in the PART A and retrieve its correspondent values as MMSI, latitude, longitude inside the same row.
The PART A
& PART B
in the reality will be about 10.000 parts, and not only 2.
In my example I used var_dump
to check all the results and the echo
to compare if I can get the right result because my data are always change.
Can you please help me on this please?