Bonjour, J'ai déjà parcouru qq sites pour trouver la solution mais sans succès. D'où viendrait l'erreur? Je vous remercie par avance voici le contenu du fichier: <?php if (!isset($_POST['debut']) ) { ?> <br> <form action="wind.php" method="POST" > <h2>Télécharger les données de n'importe quelle station du site www.wunderground.com!</h2> </br></br>Respecter ce format année-mois-jour (les chiffres doivent être séparés d'un tiret, année : 4 chiffres , mois : 2 chiffres , jour : 2 chiffres). Exemple: la rochelle 2012-01-01 2012-06-30</br></br> Cela peut durer quelques minutes avant que le fichier excel ne s'ouvre !</br></br> Station : <input name="station" value="<?php if (isset($_POST['station']) ) echo $_POST['station'] ;?>" type="text" value="La Rochelle"> Debut : <input name="debut" value="<?php if (isset($_POST['debut']) ) echo $_POST['debut'] ;?>" type="text"> Fin : <input name="fin" value="<?php if (isset($_POST['fin']) ) echo $_POST['fin'] ;?>" type="text"> <input type="submit" value="csv"/> </form> <?php } if (isset($_POST['debut']) && isset($_POST['fin'])) { $arrayUrl= array(); $station = (isset($_POST['station']) )? $_POST['station']:"La Rochelle";
$start_date = $_POST['debut']; $end_date = $_POST['fin']; $check_date = $start_date;
while ($check_date != $end_date) { $date = date ("Y", strtotime($check_date)). '/'. date ("m", strtotime($check_date)).'/'. date ("d", strtotime($check_date)); $url_data ='http://www.wunderground.com/history/airport/'.str_replace(' ',"%20",$station).'/'.$date.'/DailyHistory.html?req_city=NA&req_state=NA&req_statename=NA&format=1'; $arrayUrl[]=$url_data; $check_date = date ("Y-m-d", strtotime ("+1 day", strtotime($check_date))); } header("Content-type: application/vnd.ms-excel"); header("Content-disposition: attachment; filename=\"".$station."_".$_POST['debut']."_au_".$_POST['fin'].".csv\""); joinFiles($arrayUrl); }
// pour joindre l'ensemble des requetes et supprimer la premiere ligne des nom de colonnes function joinFiles(array $files) { // pour simuler un entete de navigateur web sinon la requete ne passe pas $agent= 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322)'; $ch = curl_init(); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_VERBOSE, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_USERAGENT, $agent); for($i = 0; $i < sizeof($files); ++$i) { curl_setopt($ch, CURLOPT_URL,$files[$i]); $data=curl_exec($ch); $data = str_replace('<br />',"\r\n",$data); $data = str_replace(',',";",$data); $array_line = explode("\n", $data); if($i>0){ //remove the line unset($array_line[1]); }
$data = implode($array_line); echo $data; }
} ?>
|