JavaScript Editor Ajax software     Free javascripts 



Main Page

6.
Create a new file in your
seophp
folder, named
read_feed.php
, and type the following code:
<?php
// load the SimplePie library
require_once ‘include/simplepie.inc’;
// create and configure SimplePie object
$feed = new SimplePie();
$feed->feed_url(‘http://seophp.example.com/feed.php’);
$feed->cache_location(‘cache’);
$feed->init();
$feed->handle_content_type();
?>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.1//EN”
“http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd”>
<html>
<head>
<title>Feed Reading Test</title>
</head>
<body>
<?php
if ($feed->data)
{
// display the title
echo ‘<h1>’ .
‘<a href=”‘ . $feed->get_feed_link() . ‘“>’ .
$feed->get_feed_title() .
‘</a>’ .
‘</h1>’;
// display a maximum of 5 feed items
$max = $feed->get_item_quantity(5);
for ($x=0; $x<$max; $x++)
{
$item = $feed->get_item($x);
// display feed link and title
echo ‘<h2>’ .
‘<a href=”‘ . $item->get_permalink() . ‘“>’ .
$item->get_title() .
‘</a>’ .
‘</h2>’;
// display feed description
echo ‘<p>’ . $item->get_description() . ‘</p>’;
}
}
?>
</body>
</html>
162
Chapter 7: Web Feeds and Social Bookmarking
c07.qxd:c07 10:42 162


JavaScript Editor Ajax software     Free javascripts