Jump to content

RSS Feeds


wiggst3r

Recommended Posts

I've used Peter Lavin's (Object Oriented PHP book) code and this works for me:

 

<?php

//point to an xml file you want to feed

$feed = "http://rss.news.yahoo.com/rss/mideast";

 

//create the object you want

$sxml = simplexml_load_file($feed);

foreach ($sxml->attributes() as $key => $value){

  echo "<p>RSS $key $value</p>\n";

}

echo "<h2>". $sxml->channel->title. "</h2>\n";

echo "<p>\n";

 

//iterate through the items

foreach ($sxml->channel->item as $item){

  $strtemp = "<a href=\"$item->link\">".

    "$item->title</a> $item->description<br /><br />\n";

  echo $strtemp;

}

echo "</p>\n";

?>

Link to comment
https://forums.phpfreaks.com/topic/126608-rss-feeds/#findComment-655002
Share on other sites

wrap your code in the code tags makes it easier to follow

 

<?php
//point to an xml file you want to feed
$feed = "http://rss.news.yahoo.com/rss/mideast";

//create the object you want
$sxml = simplexml_load_file($feed);
foreach ($sxml->attributes() as $key => $value){
  echo "<p>RSS $key $value</p>\n";
}
echo "<h2>". $sxml->channel->title. "</h2>\n";
echo "<p>\n";

//iterate through the items
foreach ($sxml->channel->item as $item){
  $strtemp = "<a href=\"$item->link\">".
    "$item->title[/url] $item->description

\n";
  echo $strtemp;
}
echo "</p>\n";
?>

Link to comment
https://forums.phpfreaks.com/topic/126608-rss-feeds/#findComment-655004
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.