Login  |  Register
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome, Guest. Please login or register.
Did you miss your activation email?

August 19, 2022, 06:05:32 AM

Login with username, password and session length
Members
  • Total Members: 3843
  • Latest: Tricky
Stats
  • Total Posts: 193479
  • Total Topics: 21088
  • Online today: 58
  • Online ever: 1035
  • (November 26, 2020, 04:45:12 AM)
Users Online
Users: 1
Guests: 42
Total: 43

Author Topic: Pulling RSS Feed Into An PHP Article  (Read 18761 times)

0 Members and 1 Guest are viewing this topic.

Max

  • Guest
Pulling RSS Feed Into An PHP Article
« on: July 25, 2006, 08:58:25 PM »
Found an eay way to display RSS Feeds in a PHP Article  :)

Copy this code below into a PHP Article....

Code: [Select]
// TP RSS Article Script

// TP Function
$context['TPortal']['rss_notitles']= false;

// Create An XML Parser
$xml_parser = xml_parser_create();

// Set The Functions To Handle Opening & Closing Tags
xml_set_element_handler($xml_parser, "startElement", "endElement");

// Set The Function To Handle Blocks Of Character Data
xml_set_character_data_handler($xml_parser, "characterData");

// Open The XML File
$fp = fopen("http://news.bbc.co.uk/rss/newsonline_world_edition/front_page/rss.xml","r")
or die("Error reading RSS data.");

// Read The XML File 4KB At A Time
while ($data = fread($fp, 4096))

// Parse Each 4KB Chunk With The XML Parser
xml_parse($xml_parser, $data, feof($fp))

// Handle errors in parsing
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 XML File
fclose($fp);

// Free Up Memory Used By XML Parser
xml_parser_free($xml_parser);

Edit:
Moved To Block code snippets to make it easier to find.
« Last Edit: July 27, 2006, 07:07:26 PM by Maxâ„¢ »

Sledge

  • Guest
Re: Pulling RSS Feed Into An PHP Article
« Reply #1 on: October 09, 2006, 09:10:22 PM »
WooHoo! Just what I've been looking for! I'm gonna try it right now.

Balrost

  • Guest
Re: Pulling RSS Feed Into An PHP Article
« Reply #2 on: December 22, 2006, 02:25:55 PM »
Hi. 

Thanx for the code works pretty good and fairly simple for us non coders. LOL  One question tho.

The code is not showing all the data from the xml doc.  Here is a sample of the xml

Code: [Select]
<item>
<title>ArkInventory (1.22)</title>
?
<link>
http://www.wowinterface.com/downloads/info6488-1.22.html
</link>
?
<description>
Overview:

 unlimited number of bars (there are practical limits though before your screen becomes full)
 assign items to a category of your choice (overrides the default assignment)
...
</description>
<author>arkayenro</author>
<category domain="http://www.wowinterface.com"/>
?
<guid>
http://www.wowinterface.com/downloads/info6488-1.22.html
</guid>
<pubDate>Fri, 22 Dec 2006 13:54:55</pubDate>
</item>

The tile shows fine, the links works, the decription shows up, but the pupDate and the author are missing.  The catagory and guid are missing as well but I dont need that info.

Any ideas of how to make these show in the rss article?

domineaux

  • Guest
Re: Pulling RSS Feed Into An PHP Article
« Reply #3 on: December 26, 2006, 10:12:06 AM »
I'd like to see a demo or site where this is happening. 

Thanks

Offline Nokonium

  • Aging Hippie
  • Friends
  • *
  • Posts: 1384
    • Our-Local
Re: Pulling RSS Feed Into An PHP Article
« Reply #4 on: December 26, 2006, 10:51:54 AM »
There is another thread on this topic

http://www.tinyportal.net/index.php?topic=11569.msg96623#msg96623

Examples of my version can be found here http://nokonium.co.uk/Fiddlers-Elbow/index.php bottom of the left sidebar (this is one of my test sites).
« Last Edit: December 26, 2006, 10:57:41 AM by nokonium »

Balrost

  • Guest
Re: Pulling RSS Feed Into An PHP Article
« Reply #5 on: December 26, 2006, 12:46:22 PM »
The rss feed can be viewed at www.hgguild.com.  In the left box area is a article called Balrot's UI rss feed.  It will bring up the article and you can see it is missing some of the data.  It uses the XML code format I posted above.

latinlives

  • Guest
Re: Pulling RSS Feed Into An PHP Article
« Reply #6 on: January 11, 2007, 03:26:38 PM »
How can I limit the number of the articles displayed?

srm

  • Guest
Re: Pulling RSS Feed Into An PHP Article
« Reply #7 on: March 20, 2007, 03:11:46 PM »
Ok Im still confused about this rss thing.

what I am trying to do is use rss feeds of the latest dance music news etc. I found a few places but they are all xml urls.

When I am making a block and I want the rss feed to display properly with working links to the articles etc. should i be putting xml urls? into the rss feed block?

example: I want some of the feeds from this page: http://chordata.info/-/104/    in a center block and also i want to be able to put some feeds just in articles only..

Anyone that can give me a few basic answers here I greatly thank you.

Offline Lesmond

  • Do what you have to!
  • Administrator
  • *
  • Posts: 3169
    • Tiny Pix... Free Image Hosting and Sharing.
Re: Pulling RSS Feed Into An PHP Article
« Reply #8 on: March 20, 2007, 03: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

Code: [Select]
// 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);
Please don't PM me for support without an invitation.


srm

  • Guest
Re: Pulling RSS Feed Into An PHP Article
« Reply #9 on: March 20, 2007, 05:08:10 PM »
so i use .rss urls for that? thats the think all the rss feeds i keep finding are in xml urls. so im a bit confused do i put in the xml url or do i need to find an rss url and put those in the block.

anyways i guess ill try both.