Article into objects

This commit is contained in:
2022-02-23 13:27:48 +01:00
parent e8e9d1ad95
commit 9f986f78f8
6 changed files with 105 additions and 31 deletions

View File

@@ -1,17 +1,11 @@
<?php
include './Article.php';
include './RSSArticle.php';
include './RSSArticleManager.php';
$url = "http://fetchrss.com/rss/6213baca199e171a5d6eacc26213babd69097e19dd230f73.xml"; /* insérer ici l'adresse du flux RSS de votre choix */
$rss = simplexml_load_file($url);
$tabArticle = array();
foreach ($rss->channel->item as $item){
$desc = explode("</div>", explode('<div class="content">', $item->description)[1]);
array_push($tabArticle, new Article($item->title, $desc[0], date_create($item->pubDate), $item->link));
}
$am = new RSSArticleManager();
$tabArticle = $am -> createArticles();
$tabArticle = $am -> sortArticles($tabArticle);
?>
@@ -27,7 +21,7 @@ foreach ($rss->channel->item as $item){
</div>
<?php
echo sizeof($tabArticle) .' articles<br /><br />';
foreach ($tabArticle as $a) {
echo $a.'<br />';
}