-
Notifications
You must be signed in to change notification settings - Fork 5
/
rss_feed.php
executable file
·47 lines (45 loc) · 1.51 KB
/
rss_feed.php
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
<?php
class blogFeed {
// Initialize Variables
public $title; // Title
public $thumbnail; // Thumbnail image
public $rss; // SimpleXML feed object
// Constructor
function __construct ($title, $image, $rss_url) {
$feed = file_get_contents($rss_url);
$this->title = $title;
$this->thumbnail = $image;
$this->rss = new SimpleXmlElement($feed);
}
// Show Info
function showFeed () {
echo '<div style="float: left; width=100px;">' . "\n";
echo '<h3>' . $this->title . '</h3>' . "\n";
echo '<img src="' . $this->thumbnail . '" width=100>' . "\n";
$entry = $this->rss->channel->item[0];
echo '<br><a href="' . $entry->link . '" title="' . $entry->title . '">' . $entry->title . "</a>\n";
echo '</div>' . "\n";
}
}
// Instantiate objects
$blog[] = new blogFeed( "Top Stories",
"http://news.bbcimg.co.uk/media/images/48353000/jpg/_48353242_48353243.jpg",
"http://feeds.bbci.co.uk/news/rss.xml"
);
$blog[] = new blogFeed( "Latest published stories",
"http://news.bbcimg.co.uk/view/1_4_4/cream/hi/news/img/red-masthead.png",
"http://feeds.bbci.co.uk/news/system/latest_published_content/rss.xml"
);
$blog[] = new blogFeed( "Also in the news",
"",
"http://feeds.bbci.co.uk/news/also_in_the_news/rss.xml"
);
$blog[] = new blogFeed( "In Pictures",
"http://newsimg.bbc.co.uk/nol/shared/img/v4/banner.jpg",
"http://newsrss.bbc.co.uk/rss/newsonline_uk_edition/in_pictures/rss.xml"
);
// Display HTML
foreach ($blog as $item) {
$item->showFeed();
}
?>