Membership is FREE – with unlimited access to all features, tools, and discussions. Premium accounts get benefits like banner ads and newsletter exposure. ✅ Signature links are now free for all. 🚫 No AI-generated (LLM) posts allowed. Share your own thoughts and experience — accounts may be terminated for violations.

RSS feeds

Status
Not open for further replies.

seeker

DNF Addict
Legacy Exclusive Member
Joined
Jun 18, 2003
Messages
4,159
Reaction score
17
Anyone know where I can get a complete resource as to what an RSS feed is (I know a little, not enough), and how one can incorporate it into a site...etc...?

I gogled it, but too much info, and not a how to etc...

Much appreciated.
 

Ross1982

Level 6
Legacy Platinum Member
Joined
Aug 3, 2004
Messages
626
Reaction score
0
It's just a news feed that lists the news or sporting results etc etc into a java scroller type thing, to install it I think it's just a copy and paste job.
 

seeker

DNF Addict
Legacy Exclusive Member
Joined
Jun 18, 2003
Messages
4,159
Reaction score
17
mmmm, in google I get all kind of results.
 

theparrot

Level 6
Legacy Exclusive Member
Joined
Mar 24, 2004
Messages
589
Reaction score
0
An RSS feed is supposed to be an XML file that meets the RSS dtd. Problem is it developed more ad hoc then it should have so there are more then one DTD for RSS that are not really compatible. So many just use regexps to parse them. ATOM is suppoed to be the format to fix this. I think that the concept itself it flawed and should be replaced.

In any case, what you need is a snippet of code to transform the rss/xml to html or whatever output format you desire. If you can't find something by tonight when I am back home I can probably dig something off my HD for you.
 

seeker

DNF Addict
Legacy Exclusive Member
Joined
Jun 18, 2003
Messages
4,159
Reaction score
17
would really appreciate it.

I am lost in the maze, and would love to have live feeds for some sites.
(as painlessly as possible)

Thanks!
 

Theo

Account Terminated
Joined
Feb 28, 2004
Messages
30,306
Reaction score
2,216
Ela Seeker. I have an instant RSS solution for Yahoo! feeds if your sites are on Windows servers. It might take a while to convert it to unix/linux servers.
 

Nexus

DNF Addict
Legacy Exclusive Member
Joined
Sep 11, 2002
Messages
1,495
Reaction score
0
RADiSTAR said:
Ela Seeker. I have an instant RSS solution for Yahoo! feeds if your sites are on Windows servers. It might take a while to convert it to unix/linux servers.
The folowing code has served me extremely well. It parses through XML content, and sends you an array you can pull data out of.
Code:
function GetXMLTreeData($data) 
{ 
  $parser = xml_parser_create('ISO-8859-1');
// xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1); 
  xml_parse_into_struct($parser, $data, $vals, $index); 
  xml_parser_free($parser); 

  $tree = array(); 
  $i = 0; 
  
  if (isset($vals[$i]['attributes'])) {
    $tree[$vals[$i]['tag']]['ATTRIBUTES'] = $vals[$i]['attributes']; 
    $tree[$vals[$i]['tag']][] = GetChildren($vals, $i);
  }
  else
    $tree[$vals[$i]['tag']][] = GetChildren($vals, $i); 
  
  return $tree; 
} 

function GetChildren($vals, &$i) 
{ 
  $children = array();     // Contains node data
  
  /* Node has CDATA before it's children */
  if (isset($vals[$i]['value'])) 
    $children['VALUE'] = $vals[$i]['value']; 
  
  /* Loop through children */
  while (++$i < count($vals))
  { 
    switch ($vals[$i]['type']) 
    { 
      /* Node has CDATA after one of it's children 
        (Add to cdata found before if this is the case) */
      case 'cdata': 
        if (isset($children['VALUE']))
          $children['VALUE'] .= $vals[$i]['value']; 
        else
          $children['VALUE'] = $vals[$i]['value']; 
        break;
      /* At end of current branch */ 
      case 'complete': 
        if (isset($vals[$i]['attributes'])) {
          $children[$vals[$i]['tag']][]['ATTRIBUTES'] = $vals[$i]['attributes'];
          $index = count($children[$vals[$i]['tag']])-1;

          if (isset($vals[$i]['value'])) 
            $children[$vals[$i]['tag']][$index]['VALUE'] = $vals[$i]['value']; 
          else
            $children[$vals[$i]['tag']][$index]['VALUE'] = ''; 
        } else {
          if (isset($vals[$i]['value'])) 
            $children[$vals[$i]['tag']][]['VALUE'] = $vals[$i]['value']; 
          else
            $children[$vals[$i]['tag']][]['VALUE'] = ''; 
		}
        break; 
      /* Node has more children */
      case 'open': 
        if (isset($vals[$i]['attributes'])) {
          $children[$vals[$i]['tag']][]['ATTRIBUTES'] = $vals[$i]['attributes'];
          $index = count($children[$vals[$i]['tag']])-1;
          $children[$vals[$i]['tag']][$index] = array_merge($children[$vals[$i]['tag']][$index],GetChildren($vals, $i));
        } else {
          $children[$vals[$i]['tag']][] = GetChildren($vals, $i);
        }
        break; 
      /* End of node, return collected data */
      case 'close': 
        return $children; 
    } 
  } 
} 

function array_detail($obj) {
  global $__level_deep;
  if (!isset($__level_deep)) $__level_deep = array();

  if (is_object($obj))
    print '[obj]';
  elseif (is_array($obj)) {
    foreach(array_keys($obj) as $keys) {
      array_push($__level_deep, "[".$keys."]");
      printa($obj[$keys]);
      array_pop($__level_deep);
    }
  }
  else print implode(" ",$__level_deep)." = $obj";
}
I've used this code to pull results from different RSS sources. Just use the "print_r" function in php to see what you got, and just refer to whichever node you need.

Here's some code to READ the RSS from a remote server, and save the latest feed locally as a text document (so you're not pull the RSS every time someone views your page):
Code:
$url = "http://rss.topix.net/rss/food/dieting.xml";
$url = parse_url($url);

$sock = fsockopen($url["host"],"80",$errno,$error);
if (!$sock)
{
  echo ("<b>Could Not Connect To Server.</b> ERROR No.: <I>$errno</I> | ERROR: <i>$error</i>");
  exit;
}$result = "";

$useragent = $_SERVER['HTTP_USER_AGENT'];

$header = "";
$header .= "GET ".$url["path"]." HTTP/1.0\r\n";
$header .= "Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg\r\n";
$header .= "Accept-Language: en-us\r\n";
$header .= "Host: ".$url["host"]."\r\n";
$header .= "User-Agent: $useragent\r\n";
$header .= "\r\n\r\n";

fputs($sock,$header);
$getcontent = 0;
while(!feof($sock)){
 if($getcontent<1 && $result!="\r\n") 
  $result = fgets($sock,128);
 else 
  {
   if($getcontent<1)$result="";
   $result .= fgets($sock,128);
   $getcontent++;
  }
}
fclose($sock);

$filename = "dieting.xml";
// Let's make sure the file exists and is writable first.
if (!file_exists($filename)||is_writable($filename)) {

   // In our example we're opening $filename in append mode.
   // The file pointer is at the bottom of the file hence 
   // that's where $result will go when we fwrite() it.
   if (!$handle = fopen($filename, 'w+')) {
         echo "Cannot open file ($filename)";
         exit;
   }

   // Write $result to our opened file.
   if (fwrite($handle, $result) === FALSE) {
       echo "Cannot write to file ($filename)";
       exit;
   }
   
   echo "Success, wrote ($result) to file ($filename)";
   
   fclose($handle);
                   
} else {
   echo "The file $filename is not writable";
}
print "<hr>";
print $result;

Finally, this code will READ the XML formatted document (using the functions I first quoted above), and display the results in HTML...
Code:
$output = file("newsfeed/dieting.xml");
$output = implode("",$output);

//In Case of Problem
if(!$output){$output = file("newsfeed/dieting_backup.xml");$output = implode("",$output);}

require_once('./newsfeed/functions_extra.php');
$output = GetXMLTreeData($output);

$feed = $output["RDF:RDF"][0]["ITEM"];

$newsfeed = "";
foreach($feed as $nf){
 //TITLE,LINK,DESCRIPTION
 $newsfeed .= "<a href=\"".$nf["LINK"][0]["VALUE"]."\" style=\"font-size:12px;color:#000000;\"><b>".$nf["TITLE"][0]["VALUE"]."</b></a><br>";
 $newsfeed .= "<small style=\"font-size:11px;color:#000000;\">".$nf["DESCRIPTION"][0]["VALUE"]."</small><br><br>";
}

$newsfeed = "<table cellpadding=10 cellspacing=0 border=0><tr><td>".addslashes($newsfeed)."</td></tr></table>";

You'll have to crawl through the details, but once it makes sense, you'll pretty much be unstoppable with grabbing RSS feeds. You just have to know a little PHP.

For a more "packaged" solution, here's a moldy oldey that you might be able to modify to your own needs.
http://www.dansteinman.com/php/pheadlines/

DEMO:
http://www.dansteinman.com/php/pheadlines/pheadlines.php3

This bad boy works like a charm, caches results, but... I'm not sure how up-to-date it is (and doesn't show examples from Yahoo's feeds).

Cheers,
~ Nexus
 

seeker

DNF Addict
Legacy Exclusive Member
Joined
Jun 18, 2003
Messages
4,159
Reaction score
17
Thanks everyone!!!

excellent resources, codes, and links. I apprciate it.
 
Status
Not open for further replies.

Who has viewed this thread (Total: 1) View details

Who has watched this thread (Total: 6) View details

The Rule #1

Do not insult any other member. Be polite and do business. Thank you!

Members Online

Premium Members

Upcoming events

Latest Listings

Our Mods' Businesses

*the exceptional businesses of our esteemed moderators

Top Bottom