Dynadot .com transfer sale, only $10.12 with coupon code DYNA12, available while supplies last, ends October 31, 2026.

RSS News Feed?

Namecheap AuctionsNamecheap Auctions
SpaceshipSpaceship
SpaceshipSpaceship
Watch

jhansen

Established Member
Impact
10
Hi,

How does one add Google/Yahoo RSS news feed to a site? I see a lot of sites with this sort of thing (ex: http://demfranchizeboyz.info/ ), but I don't know how to implement it. I've searched Google a bit about the subject before with little success. Any help would be appreciated, thank you.
 
0
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
Search for 'rss to html'

You can find a few solutions at hotscripts.com.
 
0
Close
http://magpierss.sourceforge.net/
http://www.geckotribe.com/rss/carp/
 
0
Close
ive also been tring to learn this so those links will help thx bentong
 
0
Close
You don't need that stuff - this will do it - just be sure to change the keywords for what news you want displayed where it says "KEYWORD". It is there twice.

Put that where you want the news to display - change whatever page you are making to yourpage.PHP and that's it. The website you highlighted is using something similar.

Enjoy!

Code:
<?php


set_time_limit(0);

$file = "http://news.google.com/news?q=KEYWORD&output=rss";

$rss_channel = array();
$currently_writing = "";
$main = "";
$item_counter = 0;

function startElement($parser, $name, $attrs) {
        global $rss_channel, $currently_writing, $main;
        switch($name) {
             case "RSS":
             case "RDF:RDF":
             case "ITEMS":
                  $currently_writing = "";
                  break;
             case "CHANNEL":
                  $main = "CHANNEL";
                  break;
             case "IMAGE":
                  $main = "IMAGE";
                  $rss_channel["IMAGE"] = array();
                  break;
             case "ITEM":
                  $main = "ITEMS";
                  break;
             default:
                  $currently_writing = $name;
                  break;
        }
}

function endElement($parser, $name) {
        global $rss_channel, $currently_writing, $item_counter;
        $currently_writing = "";
        if ($name == "ITEM") {
             $item_counter++;
        }
}

function characterData($parser, $data) {
     global $rss_channel, $currently_writing, $main, $item_counter;
     if ($currently_writing != "") {
          switch($main) {
               case "CHANNEL":
                    if (isset($rss_channel[$currently_writing])) {
                         $rss_channel[$currently_writing] .= $data;
                    } else {
                         $rss_channel[$currently_writing] = $data;
                    }
                    break;
               case "IMAGE":
                    if (isset($rss_channel[$main][$currently_writing])) {
                         $rss_channel[$main][$currently_writing] .= $data;
                    } else {
                         $rss_channel[$main][$currently_writing] = $data;
                    }
                    break;
               case "ITEMS":
                    if (isset($rss_channel[$main][$item_counter][$currently_writing])) {
                         $rss_channel[$main][$item_counter][$currently_writing] .= $data;
                    } else {
                         $rss_channel[$main][$item_counter][$currently_writing] = $data;
                    }
                    break;
          }
     }
}

$s_URL ='http://news.google.com/news?q=KEYWORD&output=rss';

$r_curl = curl_init();
curl_setopt($r_curl, CURLOPT_URL, $s_URL);
curl_setopt($r_curl, CURLOPT_RETURNTRANSFER, 1);
$s_data = curl_exec($r_curl);
curl_close($r_curl);


$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startElement", "endElement");
xml_set_character_data_handler($xml_parser, "characterData");
if (!xml_parse($xml_parser, $s_data, True))
 {
 die(sprintf("XML error: %s at line %d",
  xml_error_string(xml_get_error_code($xml_parser)),
  xml_get_current_line_number($xml_parser)));
 }
xml_parser_free($xml_parser);

// output HTML
 //print ("<div class=\"channelname\">" . $rss_channel["TITLE"] . "</div>");

if (isset($rss_channel["ITEMS"])) {
     if (count($rss_channel["ITEMS"]) > 0) {
          // for($i = 0;$i < count($rss_channel["ITEMS"]);$i++) {
          for($i = 0;$i < 5;$i++) {
               if (isset($rss_channel["ITEMS"][$i]["LINK"])) {
               //print ("\n<div class=\"itemtitle\"><a href=\"" . $rss_channel["ITEMS"][$i]["LINK"] . "\">" . $rss_channel["ITEMS"][$i]["TITLE"] . "</a></div>");
               } else {
               print ("\n<div class=\"itemtitle\"><b>" . $rss_channel["ITEMS"][$i]["TITLE"] . "</b></div>");
               }
                print ("<div class=\"itemdescription\">" . $rss_channel["ITEMS"][$i]["DESCRIPTION"] . "</div>");           }
     } else {
          print ("<b>There are no new articles.</b>");
     }
}

?>
 
1
Close
0
Close
Nice tools, VirusDetails.com and Whitebark.

Thanks.
 
0
Close
DomainEasy: white label portfolios are live. Enable yours.

We're social

Escrow.com
Spaceship
CryptoExchange.com
Domain Recover

NamePros updates

Quick replies: search, your most used replies, and more on every post
Quick replies are easier to find and use now. The quick reply menu has a search box. Type a few letters to find the reply you want. A...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back