Lire un fichier XML à partir d'une URL
Bonjour,
En fait j'ai un code qui marche très bien quand le parametre de ma fonction (rssReader()) est un fichier xml ("fluxRss.xml") qui se trouve el local, en revanche quand le fichier xml se trouve dans une url ("http://unsite.com/rss/fluxRss.xml"), ca ne marche plus. Pourquoi?
Code:
Code:
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
| <?php
//Recupération de flux RSS
function lit_xml($fichier,$item,$champs) {
// on lit le fichier
if($chaine = @implode("",@file($fichier))) {
// on explode sur <item>
$tmp = preg_split("^</?".$item.">^",$chaine);
// pour chaque <item>
for($i=1;$i<sizeof($tmp)-1;$i+=2)
// on lit les champs demandés <champ>
foreach($champs as $champ) {
$tmp2 = preg_split("^</?".$champ.">^",$tmp[$i]);
// on ajoute au tableau
$tmp3[$i-1][] = @$tmp2[1];
}
// et on retourne le tableau
return $tmp3;
}
}
function rssReader($fileRSS) {
$xml = lit_xml($fileRSS,"item",array("title","link"));
foreach($xml as $row) {
if (@$i < 11){
$row[0] = str_replace('<![CDATA[', '', $row[0]);
$row[0] = str_replace(']]>', '', $row[0]);
$retour = @$retour.'<a href="'.$row[1].'" class="rss">'.$row[0].'</a><br/>';
if (strlen($row[0])>47) {@$i = $i+2;}
else {@$i++;}
}
}
return $retour;
}
//Lecture d'un flux RSS
echo rssReader("http://unsite.com/rss/fluxRss.xml");//MARCHE PAS
echo rssReader("fluxRss.xml");//MARCHE
?> |
Merci d'avance,