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
| <?php
// Pour charger directement un fichier (distant ou local)
$xml = simplexml_load_file("/moonmoon/?type=atom10");
$tabRecherche = [
[
"texte" => "APEL",
"nombre" => 1,
"icone" => "/autres/icones/apel.jpg",
],
[
"texte" => "Flickr",
"nombre" => 1,
"icone" => "/autres/icones/flickr.jpg",
],
[
"texte" => "PCHBlog",
"nombre" => 1,
"icone" => "/autres/icones/PCH.jpg",
],
[
"texte" => "Twitter",
"nombre" => 2,
"icone" => "/autres/icones/twitter.jpg",
],
[
"texte" => "Twitter-2",
"nombre" => 2,
"icone" => "/autres/icones/twitter.jpg",
],
[
"texte" => "WebNews",
"nombre" => 2,
"icone" => "/autres/icones/standre.jpg",
],
// dernier élément pour détecter les inconnus
[
"texte" => "",
"nombre" => 2,
"icone" => "/icones/inconnu.jpg",
],
];
//variables compteurs
$totalMax = 5;
echo '<p>';
foreach ($xml->entry as $item) {
$test = explode(" : ", $item->title, 2);
foreach ($tabRecherche as $index => $r) {
if (0 === $r["nombre"]) {
// le nombre maxmimum pour cet élément a été atteint
continue;
}
if ( ("" === $r["texte"])
|| ($test[0] === $r["texte"])
) {
// affichage
echo "{$r["icone"]}<img src=\"{$r["icone"]}\" alt=\"{$test[0]}\"/>";
echo "<a href=\"{$item->link['href']}\">{$test[1]}</a>";
echo "<br/>";
// mise à jour des compteurs
$tabRecherche[$index]["nombre"]--;
$totalMax--;
// fin du parcours des textes à rechercher
break;
}
}
if (0 === $totalMax) {
// sortie de la boucle de parcours des entrées
break;
}
}
echo '</p>'; |
Partager