1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
|
setlocale(LC_TIME, "fr_FR"); // ou "fr"
$partner = "";
$ville = "SZXX0010"; $vname="Delémont";
$jours = 2;
$url = "http://xoap.weather.com/weather/local/".$ville."?cc=*&unit=s&dayf=".$jours;
// Conversion Fahrenheit->Celsius
function f2c($t) { return round(($t-32)*5/9); }
// Lecture d'un fichier XML
function lit_xml($chaine,$isFile,$item,$champs) {
// on lit le fichier ou la chaîne
if($isFile) { $chaine = @file_get_contents($chaine); }
if($chaine) {
// on explode sur <item>
$tmp = preg_split("/<\/?".$item.">/",$chaine);
// pour chaque <item>
for($i=1;$i<sizeof($tmp);$i++)
// on lit les champs demandés <champ>
foreach($champs as $champ) {
$tmp2 = preg_split("/<\/?".$champ.">/",$tmp[$i]);
// on ajoute au tableau
$tmp3[$champ][] = trim(@$tmp2[1]);
}
// et on retourne le tableau
return @$tmp3;
}
}
//---------------
$ch = curl_init($url);
//curl_setopt($ch,CRULOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_NOBODY, FALSE);
$response = curl_exec($ch);
curl_close($ch);
$url=$response;
//echo $url;
//-----------------
//$url="meteo/SZXX0010.xml";
// Extraction primaire
$xml = lit_xml($url,true,"day d=.*",array("hi","low","part p=\"d\"","part p=\"n\""));
// Extraction des icones, messages et du taux d'humidité
for($i=0;$i<$jours;$i++) {
$tmp = preg_split("/<\/?icon>/",$xml["part p=\"d\""][$i]);
$xml["icond"][$i] = $tmp[1];
$tmp = preg_split("/<\/?t>/",$xml["part p=\"d\""][$i]);
$xml["altd"][$i] = $tmp[1];
$tmp = preg_split("/<\/?hmid>/",$xml["part p=\"d\""][$i]);
$xml["hmid"][$i] = $tmp[1];
$tmp = preg_split("/<\/?icon>/",$xml["part p=\"n\""][$i]);
$xml["iconn"][$i] = $tmp[1];
$tmp = preg_split("/<\/?t>/",$xml["part p=\"n\""][$i]);
$xml["altn"][$i] = $tmp[1];
}
?>
<STYLE type="text/css">
<!--
.titre { color: #000000 }
.sstitre { color: #858586 }
.Style2 {
font-family: Arial, Helvetica, sans-serif;
font-size: 10px;
}
.Style3 {
color: #858586;
font-family: Arial, Helvetica, sans-serif;
font-size: 10px;
}
.Style4 {font-family: Arial, Helvetica, sans-serif; font-size: 10px; color: #000000; }
.date {
font-family: Verdana, sans-serif;
font-size: 12px;
font-style: normal;
line-height: normal;
font-weight: normal;
color: #0493CF
}
-->
</STYLE>
<table width="100%">
<? for($i=0;$i<$jours;$i++) { ?>
<tr>
<td class=corps><table width="100%">
<tr>
<td colspan=3 class="date">
<?=ucfirst(strftime("%A %d %B %Y",time()+$i*24*3600))?>
</strong></font></td>
</tr>
<tr>
<td width="352" class="date"><font color="#000000">Max:
<?=($xml["hi"][$i]=="N/A")?"N/A":f2c($xml["hi"][$i])."°C"?>
</font></td>
<td width="295" class=Style4><font color="#000000">JOUR</font></td>
<td width="318" class=Style4><font color="#000000">NUIT</font></td>
</tr>
<tr>
<td class="Style4"><font color="#000000">Min:
<?=($xml["low"][$i]=="N/A")?"N/A":f2c($xml["low"][$i])."°C"?>
</font></td>
<td rowspan=2 class="Style2"><font color="#000000"><img src="meteo/img/<?=$xml["icond"][$i]?>.png" alt="<?=$xml["altd"][$i]?>"
width=40></font></td>
<td rowspan=2 class="Style2"><font color="#000000"><img src="meteo/img/<?=$xml["iconn"][$i]?>.png" alt="<?=$xml["altn"][$i]?>"
width=40></font></td>
</tr>
<tr>
<td class="Style4"><font color="#000000">H%:
<?=$xml["hmid"][$i]?>
</font></td>
</tr>
</table></td>
</tr>
<? } ?>
</table> |
Partager