I need to extract all columns header with SODA Api.
I didn't found a solution with API, so I create this code. But in some cases the title of the column is different from the column api name...
There's a better solution?
//return the Dataset Columns Header
public function getDatasetColumnsHeader($dataset) {
$file = "https://www." . $this->root_url . "/resource/" . $dataset . ".csv";
$f = fopen($file, 'r');
$line = fgets($f);
fclose($f);
return explode(",", $line);
}
Oh, I found the solution:
//return the Dataset Columns Header
public function getDatasetColumnsHeader2($dataset) {
$url = "https://www." . $this->root_url . "/resource/" . $dataset . ".csv";
$header = get_headers($url, 1);
$return = array();
eval('$return = ' . $header["X-SODA2-Fields"] . ';');
return $return;
}