-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathfeed.php
55 lines (43 loc) · 1.34 KB
/
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
48
49
50
51
52
53
54
55
<?php
// The only thing we need is include base class file
require_once('FeedParser.php');
// Get XML serialization of feed
$xml = file_get_contents($_POST['filename']);
// This is great. To work with feed we invoke only base class. All other work is
// transparent.
$feed = new FeedParser($xml);
//Because we have interface for feeds, we invoke interface methods
echo '<b>Type:</b>'.$feed->getFeedType()."<br/>";
echo '<b>Title:</b>'.$feed->getTitle()."<br/>";
echo '<b>Description:</b>'.$feed->getDescription()."<br/>";
echo '<b>Feed link:</b>'.$feed->getFeedLink()."<br/>";
echo '<b>Link:</b>'.$feed->getLink()."<br/>";
$items = $feed->getItems();
// Stuff in your items can be empty, so you should somehow handle it.
// I've prepared is_empty function for you - enjoy.
$i=1;
foreach($items as $item)
{
//Because we have interface for items, we invoke interface methods
echo "<h1>";
if(is_empty($item->getLink()))
echo '<a href="#">';
else
echo '<a href="'.$item->getLink().'">';
if(is_empty($item->getTitle()))
echo "No title";
else
echo "$i. ".$item->getTitle();
echo "</a>";
echo "</h1>";
if(is_empty($item->getPubDate()))
echo "<i>"."No date"."</i><br/>";
else
echo "<i>".$item->getPubDate()."</i><br/>";
if(is_empty($item->getContent()))
echo "<i>"."No content"."</i><br/>";
else
echo $item->getContent()."<hr/>";
$i++;
}
?>