function pleiades_get_latest_export() { $z = new ZipArchive(); $gzfile = "pleiades-names-latest.csv.gz"; $gzcontents = file_get_contents("http://atlantides.org/downloads/pleiades/dumps/$gzfile"); // Make sure you can write to this directory: $gzlocalfile = "/uploads/pleiades/$gzfile"; if (!file_put_contents($gzlocalfile,$gzcontents)) { die("Could not save Pleiades import file: $gzfile. Check that you have write permissions!"); } $lines = gzfile($gzlocalfile); $pleiades_locations = Array(); $i = 0; foreach ($lines as $line) { $loc_array = csv2array($line); $loc = $loc_array[0]; if ($i == 0) { $keys = $loc; } else if ($i > 1) { $index = 0; foreach ($loc as $key=>$value) { $loc_keyed[$keys[$index]] = $value; $index++; } $pleiades_locations[] = $loc_keyed; } $i++; } return $pleiades_locations; } function csv2array($input, $delimiter=',', $enclosure='"', $escape=null, $eol=null) { $temp=fopen("php://memory", "rw"); fwrite($temp, $input); fseek($temp, 0); $r = array(); while (($data = fgetcsv($temp,4096,',','"')) !== false) { $r[] = $data; } fclose($temp); return $r; }