data = $data; $this->type = $type; $this->structure(); $this->prepareData(); } protected function prepareData() { $row = 0; foreach($this->data as $itemKey => $itemVal) { foreach($this->enteteKey as $key){ $val = html_entity_decode($itemVal->$key); $this->list[$row][] = $val; } $row++; } } protected function structure() { switch($this->type) { case 'rechercheEntreprise': $structure = array( 'Siren' => 'Siren', 'Nom' => 'Nom', 'Nom2' => 'Nom2', 'Enseigne' => 'Enseigne', 'Adresse' => 'Adresse', 'Adresse2' => 'Adresse2', 'CP' => 'CP', 'Ville' => 'Ville', 'Sigle' => 'Sigle', 'Siege' => 'Siege', 'Actif' => 'Actif', 'FJ' => 'FJ', 'FJLib' => 'FJLib', 'NafEnt' => 'NafEntLib', ); break; default: break; } $this->entete = array_values($structure); $this->enteteKey = array_keys($structure); } public function writeFile($filename) { $fp = fopen($filename, 'w'); if (count($this->entete)>0){ fputcsv($fp, $this->entete); } foreach ($this->list as $fields) { $fields = array_map('htmlspecialchars_decode', $fields); fputcsv($fp, $fields); } fclose($fp); } }