parsing XML with SimpleXML
Source code
1
<?php include('./.config.php');
2 /*
3 using PHP 5's SimpleXML to parse an RSS Feed
4 */
5 include('./.fetch_xml_with_socket.php5');
6
7 $rss = simplexml_load_string(fetchRss("rss.news.yahoo.com","/rss/oddlyenough"));
8
9 $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
Last update 24-Apr-2005 4:28 pm | up | list examples | home