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
| <?
// Lecture d'un fichier XML
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;
}
}
// Exemple : title > 0 lien > 1 description > 2 date > 3 reference dvd > 4 reference video > 5 thumb_principale > 6
$xml = lit_xml("http://www.dailymotion.com/rss/user/TvAzteca/1","item",array("title","link","description","media:thumbnail", "dm:id"));
// et on affiche...
echo "<?xml version='1.0' encoding='ISO-8859-15'?>
<rss version='2.0'>
<channel>
<title>Dayli TvAzteca</title>
<link>http://www.TvAzteca.com</link>
<description>Dayli TvAzteca</description> ";
foreach($xml as $row) {
echo "<item>"
."<title>".$row[0]."</title>"
."<link>".$row[1]."</link>"
."<description>".$row[2]."</description>"
."<enclosure url='".$row[3]."' length='50000' type='image/jpeg'"."/>"
."<guid>".$row[4]."</guid>"
."</item>";
}
echo "</channel>
</rss>
";
?> |
Partager