parsing XML with SimpleXML

Source code


<?php include('./.config.php');
/*
using PHP 5's SimpleXML to parse an RSS Feed
*/
include('./.fetch_xml_with_socket.php5');

$rss simplexml_load_string(fetchRss("rss.news.yahoo.com","/rss/oddlyenough"));

$count=0;
10 
11 
// display the top ten
12 
13 
foreach ($rss->channel->item as $item) {
14     
$count++;
15     
printf('<p><strong><a href="%s">%s</a></strong><br />%s</p>',
16         
$item->link,
17         
$item->title,
18         
$item->description);
19     if (
$count == 10) { break;}
20 }
21 echo 
"<p>total $count</p>" ;
22 include(
'./.footer.php')?>

Output


Notice: Trying to get property of non-object in /home/davidmintz/www/davidmintz.org/php_course/examples/10/simpleXML_rss.php5 on line 13

Notice: Trying to get property of non-object in /home/davidmintz/www/davidmintz.org/php_course/examples/10/simpleXML_rss.php5 on line 13

Warning: Invalid argument supplied for foreach() in /home/davidmintz/www/davidmintz.org/php_course/examples/10/simpleXML_rss.php5 on line 13

total 0

previous: caching/parsing RSS with PEAR XML_RSS
next: caching/parsing XML with SimpleXML


Last update 24-Apr-2005 4:28 pm | up | list examples | home