parent
3f78318f08
commit
db0faf02d4
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
class RssParser
|
||||
{
|
||||
|
||||
public function getResultFlux($url)
|
||||
{
|
||||
ini_set('display_errors', 1);
|
||||
ini_set('user_agent', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; rv:1.7.3) Gecko/20041001 Firefox/0.10.1');
|
||||
|
||||
$listeArticles = array();
|
||||
|
||||
if (!($x = simplexml_load_file($url)))
|
||||
return;
|
||||
|
||||
foreach ($x->channel->item as $item)
|
||||
{
|
||||
$title = $item->title;
|
||||
$description = $item->description;
|
||||
$pubdate = $item->pubDate;
|
||||
$link = $item->link;
|
||||
$listeArticles[] = new News($title,$description,$pubdate,$link);
|
||||
|
||||
// Create summary as a shortened body and remove images,
|
||||
// extraneous line breaks, etc.
|
||||
//$post->summary = $this->summarizeText($post->text);
|
||||
}
|
||||
|
||||
return $listeArticles;
|
||||
}
|
||||
}
|
||||
?>
|
@ -0,0 +1,23 @@
|
||||
<html>
|
||||
<body>
|
||||
<?php
|
||||
include("news.php");
|
||||
include ('RssParser.php');
|
||||
|
||||
$parser = new RssParser();
|
||||
$resultFlux = $parser->getResultFlux("https://www.lemonde.fr/sciences/rss_full.xml");
|
||||
foreach($resultFlux as $n){
|
||||
echo $n->getTitle();
|
||||
echo "</br>";
|
||||
echo $n->getPubdate();
|
||||
echo "</br>";
|
||||
echo $n->getLink();
|
||||
echo "</br>";
|
||||
echo $n->getDescription();
|
||||
echo "</br>";
|
||||
echo "</br>";
|
||||
}
|
||||
|
||||
?>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in new issue