TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

Members
  • Total Members: 3,963
  • Latest: BiZaJe
Stats
  • Total Posts: 195,917
  • Total Topics: 21,308
  • Online today: 884
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online
  • Users: 0
  • Guests: 310
  • Total: 310

Pulling RSS Feed Into An PHP Article

Started by Max, July 26, 2006, 03:58:25 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

JSW

With this code is it possible to add the scrolling feature? I like that this uses the actual .rss extension because the links work. I've tried the other rss feed codes but the links don't link properly. I've tried to add the scroll code myself to this code but I'm a newbie and it don't work. So any help would be appreciated. Thanks

Quote from: Lesmondâ„¢ on March 20, 2007, 09:29:04 PM
I have a PHP version here you could try works in any block or article, not tested it with xml feeds though

// An RSS Reader to grab news from whichever site you choose
$backend = "Place feed here inside the qoutes "; //change this to match the rss feed url you wish to display.
// end


function endtheElement($parser, $tagName) {
// This function is used when an end-tag is encountered.
global $insideitem, $tag, $title, $description, $link;
 
  if ($tagName == "ITEM") {
    echo '<table width="100%" border="0"><tr>
      <td class="main-table">
      <span class="nav-head"><strong>
      ';
    printf("<p><b><a href='%s'>%s</a></b></p>", // make our title into an actual link
    trim($link),htmlspecialchars(trim($title))); // remove html characters from the title
 
    echo "</tr>";
    echo '<tr>
      <td class="nav">';
    printf("<p>%s</p>",$description); // Print out the live journal entry
    echo"</td>";
    echo "</tr>";
    echo "</table>";
    echo "<br>";
    $title = $description = $link = $insideitem = false;
   }
}

// Now to the parsing itself. Starts by creating it:

$xml_parser = xml_parser_create();

// Then setup the handlers:

xml_set_element_handler($xml_parser, "startElement", "endElement");
xml_set_character_data_handler($xml_parser, "characterData");

// Open the actual datafile:

$fp = fopen($backend, r);

// Run through it line by line and parse:

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)));
}

// Close the datafile

fclose($fp);

// Free any memmory used

xml_parser_free($xml_parser);


Freddy

Do you mean a marquee ? LIke this :

News..

JSW

No, sorry for not explaining properly.

I want that code I posted because it posts rrs feeds properly and links properly, unlike the other rrs codes that I've tried. I put this code into a block and it works perfectly. The links all work. The only issue is that the block box is huge. I'd like to be able to control it in a block box that is 200 in height and have it scroll up. I'm not sure if that's possible to do with this code but if so, it'd be perfect for me.

The other rrs codes I've tried on here work but the links don't work. They try to link within my website url and when clicked they give an error. I'm using rrs feeds from a twitter account.

Freddy

Try this :

// An RSS Reader to grab news from whichever site you choose
$backend = "http://newsrss.bbc.co.uk/rss/newsonline_uk_edition/technology/rss.xml"; //change this to match the rss feed url you wish to display.
// end

// Now to the parsing itself. Starts by creating it:

$xml_parser = xml_parser_create();

// Then setup the handlers:

xml_set_element_handler($xml_parser, "startElement", "endElement");
xml_set_character_data_handler($xml_parser, "characterData");

// Open the actual datafile:

$fp = fopen($backend, r);

echo '
<div style="height: 200px;width: 100%;overflow-x:hidden;overflow-y:auto">';

// Run through it line by line and parse:

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)));
}

echo '
</div>';

// Close the datafile

fclose($fp);

// Free any memmory used

xml_parser_free($xml_parser);



You don't seem to be using that endtheElement function so I removed it.  Easy enough to put it back in...   I put the whole output inside a DIV and gave you scrolling on the right hand side.

Hope that's what you meant :)

This website is proudly hosted on Crocweb Cloud Website Hosting.