array(), "name_array" => array(), "latitude_array" => array(), "longitude_array" => array(), "coord_accuracy_array" => array(), "begin_date_array" => array(), "end_date_array" => array() ); private $input_file; private $input_line; private $input_fields = array(); private $point_count = 0; private $output_file; private $return_string = ""; // public function checkCSVFile($input_file_path) { // check number of input_fields // check the used field delimiter // check first line : column headers or not ? // check each field, common errors like lat/lon switching // } // function checkCSVFile public function readPointsFromCSVFile($input_file_path) { $this->point_count = 0; $this->input_file = fopen($input_file_path,"r"); $this->input_line = trim(fgets($this->input_file)); while (!feof($this->input_file)) { // for the moment, we expect the delimiter to be a blank space // TODO : make this dynamic with a parameter $this->input_fields = explode(",", $this->input_line); $this->points_array["id_array"][$this->point_count] = $this->input_fields[0]; $this->points_array["name_array"][$this->point_count] = $this->input_fields[1]; $this->points_array["latitude_array"][$this->point_count] = $this->input_fields[2]; $this->points_array["longitude_array"][$this->point_count] = $this->input_fields[3]; $this->points_array["coord_accuracy_array"][$this->point_count] = $this->input_fields[4]; $this->points_array["begin_date_array"][$this->point_count] = $this->input_fields[5]; $this->points_array["end_date_array"][$this->point_count] = $this->input_fields[6]; $this->input_line = trim(fgets($this->input_file)); $this->point_count++; } fclose($this->input_file); return($this->points_array); } //function readPointsFromCSVFile public function writePointsToCSVFile($points_array,$structure_array,$output_file_path) { $this->point_count = 0; $this->output_file = fopen($output_file_path,'w'); // TODO : column headers could come straight from the points array keys // with a foreach-loop : that would be nicer and more dynamic fwrite ($this->output_file,"unique_id id name lat lon accuracy begin_date end_date\n"); //fwrite ($this->output_file," "); // foreach ($points_array["unique_id_array"] as $dummy) { foreach ($structure_array["route_array"] as $dummy) { // TODO : it would be neat to do this with an "explode" function, but // array structure has to be adapted for that // TODO : leave the choice of delimiter fwrite ($this->output_file,$points_array["unique_id_array"][$this->point_count]); fwrite ($this->output_file,","); fwrite ($this->output_file,$points_array["id_array"][$this->point_count]); fwrite ($this->output_file,","); fwrite ($this->output_file,$points_array["name_array"][$this->point_count]); fwrite ($this->output_file,","); fwrite ($this->output_file,$points_array["latitude_array"][$this->point_count]); fwrite ($this->output_file,","); fwrite ($this->output_file,$points_array["longitude_array"][$this->point_count]); fwrite ($this->output_file,","); fwrite ($this->output_file,$points_array["coord_accuracy_array"][$this->point_count]); fwrite ($this->output_file,","); fwrite ($this->output_file,$points_array["begin_date_array"][$this->point_count]); fwrite ($this->output_file,","); fwrite ($this->output_file,$points_array["end_date_array"][$this->point_count]); fwrite ($this->output_file,"\n"); $this->point_count++; } // foreach fclose($this->output_file); return($this->returnString); } // function writePointsToCSVFile } // class CSV_module ?>