Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6859607
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:18:16+00:00 2026-05-27T02:18:16+00:00

I am trying to generate an RSS feed on my site using the code

  • 0

I am trying to generate an RSS feed on my site using the code below. The rss is appearing but I am having two issues:

  1. When the feed shows on my page the images do not show up, instead you see the img link appear directly on the page like this… <a href="http://movies.nytimes.com/2011/11/18/movies/garbo-the-spy-about-juan-pujol-garcia-review.html?partner=rssnyt&emc=rss"><img src="http://graphics8.nytimes.com/images/2011/11/18/movies/18RDP_GARBO/18RDP_GARBO-thumbStandard.jpg" border="0" height="75" width="75" hspace="4" align="left"></a>

  2. How do I limit the amount of articles that appear on my site?

Here is the link to the RSS: Spy RSS FEED
Here is the code I am using:

    <?php
$insideitem = false;
$tag = "";
$title = "";
$description = "";
$link = "";
$locations = array('http://topics.nytimes.com/topics/reference/timestopics/subjects/e/espionage/index.html?rss=1');
srand((float) microtime() * 10000000); // seed the random gen 
$random_key = array_rand($locations);
function startElement($parser, $name, $attrs) {
 global $insideitem, $tag, $title, $description, $link;
 if ($insideitem) {
  $tag = $name;
 } elseif ($name == "ITEM") {
  $insideitem = true;
 }
}
function endElement($parser, $name) {
 global $insideitem, $tag, $title, $description, $link;
 if ($name == "ITEM") {
  printf("<dt><b><a href='%s' target=new>%s</a></b></dt>",
  trim($link),htmlspecialchars(trim($title)));
  printf("<dt>%s</dt><br><br>",htmlspecialchars(trim($description)));
  $title = "";
  $description = "";
  $link = "";
  $insideitem = false;
 }
}
function characterData($parser, $data) {
 global $insideitem, $tag, $title, $description, $link;
 if ($insideitem) {
 switch ($tag) {
  case "TITLE":
  $title .= $data;
  break;
  case "DESCRIPTION":
  $description .= $data;
  break;
  case "LINK":
  $link .= $data;
  break;
 }
 }
}
$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startElement", "endElement");
xml_set_character_data_handler($xml_parser, "characterData");
$fp = fopen($locations[$random_key], 'r')
 or die("Error reading RSS data.");
while ($data = fread($fp, 4096))
 xml_parse($xml_parser, $data, feof($fp))
  or die(sprintf("XML error: %s at line %d",
   xml_error_string(xml_get_error_code($xml_parser)),    
   xml_get_current_line_number($xml_parser)));
fclose($fp);
xml_parser_free($xml_parser);
?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T02:18:16+00:00Added an answer on May 27, 2026 at 2:18 am

    In endElement(), when outputting the feed content, it calls printf("<dt>%s</dt><br><br>",htmlspecialchars(trim($description)));

    If you remove the htmlspecialchars function, then it should display images and other html properly instead of converting < to &lt; etc.

    Given that code, there is no built in way to limit the number of feeds. Nytimes may have an option you can pass as part of the query string that restricts the number of results, but I am not sure about that.

    A quick fix would be to add a global variable called $numShown or something like that, and at the beginning of endElement(), you can increment it, and the check to see if it is above some value and if so just return prior to all the printf calls to output the feed item.

    <?php
    
    function endElement($parser, $name) {
        global $insideitem, $tag, $title, $description, $link, $numShown;
    
        if ($name == "ITEM") {
            $numShown++;
    
            if ($numShown >= 5) {
                return ;
            }
    
            printf ( "<dt><b><a href='%s' target=new>%s</a></b></dt>", trim ( $link ), htmlspecialchars ( trim ( $title ) ) );
            printf ( "<dt>%s</dt><br><br>", trim ( $description ) );
            $title = "";
            $description = "";
            $link = "";
            $insideitem = false;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to generate a Google Merchant RSS Feed, using PHP's SimpleXML and
Im trying to generate RSS page with CListView but i got additional generated html
I'm trying to generate code coverage reports with EMMA using tests of which some
I am trying to generate a full rss feed, however when loading the feed
I am trying to generate a RSS feed from a mysql database I already
I'm trying to generate some code at runtime where I put in some boiler-plate
I've created a rudimentary RSSActionResult in ASP.NET MVC to generate an RSS feed based
I'm trying to generate a pdf file from data in a database using JasperReports
I am trying to publish an Atom/RSS feed in my Java based Google App
I am trying to generate a PDF using iTextSharp. It will consists of a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.