Programming Tools
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingProgramming Tools

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old November 5th, 2002, 08:53 PM
mytch mytch is offline
Dev Articles Novice (500 - 999 posts)
 
Join Date: Apr 2002
Location: Sydney, Australia
Posts: 589 mytch User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Article Discussion: Building a Generic RSS Class With PHP

Building a Generic RSS Class With PHP If you have any questions or comments about this article then please post them here.

You can read the article here .

Reply With Quote
  #2  
Old November 6th, 2002, 10:27 AM
philringnalda philringnalda is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 3 philringnalda User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Invalid RSS

Sadly, what you have here is an example of how confusing the multiple RSS specs can be.

In 0.90/1.0, image and items are children of the root rdf:RDF element, in 0.91/2.0 they are children of the channel element. But you are building a mishmash, a file that claims to be 0.91, with an 0.91 root element, but 0.90/1.0 structure. To compound the confusion, on page two you discuss building up this 0.90.5ish file, with a doctype and an rss root element, and then present an 0.90 file with no doctype and an rdf:RDF root element for validation.

Reply With Quote
  #3  
Old November 7th, 2002, 09:44 AM
nhoizey nhoizey is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Location: Paris, France
Posts: 1 nhoizey User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RSS feeds by topic?

Hi,

nice article, even if I learned nothing, being a RSS user for a while...

I have indeed created a small and simple PHP class that does exactly the opposite of yours: it take the URL of a RSS feed, and changes it to HTML code. it is called phpSyndication, and is available here: URL

Anyway, I just would like to know why devArticles proposes just one general RSS feed, instead of this general and one for each topic, such as PHP or ASP? I would like for example to put devArticles' RSS feeds on phpHeaven, but I'm obviously only interested in PHP articles...

On phpHeaven, RSS feeds are available on base of each directory of the content tree, so that you can syndicate only the one you need.

Regards,

Nicolas.

Reply With Quote
  #4  
Old December 25th, 2002, 06:08 PM
bdegroodt bdegroodt is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Location: New York City
Posts: 3 bdegroodt User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
sample?

Hey Mitch-

Do you have an .xml file location that shows the output format from this? I'd like to run it through a RSS validator before I start hacking away at this with my own personal changes to it.

Thanks!

Reply With Quote
  #5  
Old December 25th, 2002, 07:35 PM
philringnalda philringnalda is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 3 philringnalda User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
It's not valid RSS, but it's not too difficult to make it valid: mostly you just need to move the line in class.myRSS.php that writes the </channel> tag down to immediately above the line that writes the </rss> tag, since in RSS 0.91 items are inside the channel, not outside. However, if there's the slightest chance that your titles or descriptions will ever have quotes, apostrophes, ampersands, or less-than or greater-thans in them (or if they contain HTML), it's a good idea to run them through htmlspecialchars to escape anything that will cause you to produce invalid XML:

PHP Code:
 $rssValue .= "<title>" htmlspecialchars($rRow[$titleFieldName], ENT_QUOTES) . "</title>\r\n";
$rssValue .= "<description>" htmlspecialchars($rRow[$descFieldName], ENT_QUOTES) . "</description>\r\n"

Reply With Quote
  #6  
Old December 26th, 2002, 06:39 PM
bdegroodt bdegroodt is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Location: New York City
Posts: 3 bdegroodt User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I don't know. I tried to add URL to NewzCrawler and it isn't going for it. Sends back an error "Error Parsing XML: Unsupported Newsfeed Format"

When trying to add this sample from my server, I get "Failed: Zero Length Reply." (URL)

Is this because the file ends in .php vs .xml? Is it NewzCrawler?


Reply With Quote
  #7  
Old December 27th, 2002, 10:00 PM
philringnalda philringnalda is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 3 philringnalda User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Looks to be a NewzCrawler problem - I added your feed in half a dozen other RSS readers with no problem, and in fact if you uncheck NewzCrawler's "download and verify" option while adding it, it works just fine in NewzCrawler. It's not the .php that's the problem - I added several of my own .php feeds to NewzCrawler without getting that "zero length reply." Dunno, at this point I can't even remember why I stopped using NewzCrawler.

Reply With Quote
  #8  
Old December 28th, 2002, 09:17 AM
bdegroodt bdegroodt is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Location: New York City
Posts: 3 bdegroodt User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Yeah I verified my feed and the devarticles feed through a couple of RSS validators and passed with flying colors.

I'm able to add my feed and the devarticles feed to NewzCrawler, by unchecking the verify feature, but it won't pull news back-just adds the feed location, but no data.

Any suggestions for an alternate, yet fully featured reader besides NewzCrawler?

Also, on a different note, is it acceptable for the feed location to have variables at the end of the URL? For instance, URL ? Or does the standard call for specific extensions (.xml, .php, .asp etc)?

Finally, I wrote Ben Hammersley (Author of an upcoming RSS book on O'Reilly) about the status of RSS in general. Do you think it's on the upswing, downswing or just kind of neutral right now? It's seems odd to me that it's been sitting around as a standard (Even if an evolving one.) for some time, but main street isn't too aware of it.

Thanks!

Reply With Quote
  #9  
Old April 15th, 2003, 01:44 PM
Driekd Driekd is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Posts: 1 Driekd User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I don't understand.

What is for what file ?

Can you post each code for each page togetter ?

example
--------------
* rss.xml
--------------
code code

Reply With Quote
  #10  
Old August 25th, 2003, 05:37 AM
rcknierim rcknierim is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 1 rcknierim User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
image/url in description tag

Hi,

I used the script from this article and it works fine.

But I also want to add an URL or image into the description tag. If I want to add an URL for example, I get the following:

<item>
<title>Auto pech. Maar het komt goed.</title>
- <description>
<a href="test">test</a>
</description>
<link>URL</link>
</item>

It makes a tag from the URL.

I want the URL to be part of the description tag.

Anyone knows how to do this?

Thanks!

Reply With Quote
  #11  
Old May 1st, 2004, 01:34 PM
nbostic nbostic is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 1 nbostic User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Unhappy

Okay, I read through this and I'll admit, I'm not the greatest with either PHP or XML or RSS, but I'm trying to learn. Here's what I've done:

test.php
PHP Code:
<?php
  
include("http://www.happy-hour.org/class.myRSS.php");
  
  
// Instantiate the myRSS class
  
$myRSS = new myRSS;
  
  
$myRSS->channelTitle "Happy Hour Directory";
  
$myRSS->channelLink "http://www.happy-hour.org";
  
$myRSS->channelDesc "Happy Hour Dining Directory Latest Additions";
  
  
$myRSS->imageTitle "Happy Hour Directory";
  
$myRSS->imageLink "http://www.happy-hour.org/images/logo.png";
  
$myRSS->imageURL "http://www.happy-hour.org";
  
  
// Get the RSS data
 
$rssData $myRSS->GetRSS("hostname""username""password""databasename""tablename""name""description""dineID""http://www.happy-hour.org/details/{dineID}/");
  
  
// Output the generated RSS XML
  
header("Content-type: text/xml");
  echo 
$rssData
  
?>


class.myRSS.php
PHP Code:
<?php
  
class myRSS
  
{
  
// Create our channel variables
  
var $channelTitle;
  var 
$channelLink;
  var 
$channelDesc;
  
  
// Create our image variables
  
var $imageTitle;
  var 
$imageLink;
  var 
$imageURL
  
  function 
checkValues()
  {
  
// Make sure all channel and image values are set
  
if($this->channelTitle == "")
  die(
"Please specify a channel title");
  
  if(
ereg("$http://"$this->channelLink) == false)
  die(
"Please specify a channel link");
  
  if(
$this->channelDesc == "")
  die(
"Please specify a channel description");
  
  if(
$this->imageTitle == "")
  die(
"Please specify an image title");
  
  if(
ereg("$http://"$this->imageLink) == false)
  die(
"Please specify an image link");
  
  if(
ereg("$http://"$this->imageURL) == false)
  die(
"Please specify an image URL");
  } 
  
  
// Connect to the database, generate the RSS XML and return it
 
function GetRSS($dbServer$dbUser$dbPass$dbName$tableName$titleFieldName$descFieldName$linkFieldName$linkTemplate)
  {
  
// Make sure all channel/image values have been set
  
$this->checkValues(); 
  
  
$rssValue "<?xml version=\"1.0\"?>\r\n";
 
$rssValue .= "<!DOCTYPE rss PUBLIC \"-//Netscape Communications//DTD RSS 0.91//EN\" \"http://my.netscape.com/publish/formats/rss-0.91.dtd\">\r\n";
  
$rssValue .= "<rss version=\"0.91\">\r\n";
  
  
// Build the channel tag
  
$rssValue .= "<channel>\r\n";
  
$rssValue .= "<title>" $this->channelTitle "</title>\r\n";
  
$rssValue .= "<link>" $this->channelLink "</link>\r\n";
  
$rssValue .= "<description>" $this->channelDesc "</description>\r\n";
  
$rssValue .= "<language>en-us</language>\r\n";
  
$rssValue .= "</channel>\r\n";
  
  
// Build the image tag
  
$rssValue .= "<image>\r\n";
  
$rssValue .= "<title>" $this->imageTitle "</title>\r\n";
  
$rssValue .= "<url>" $this->imageURL "</url>\r\n";
  
$rssValue .= "<link>" $this->imageLink "</link>\r\n";
  
$rssValue .= "</image>\r\n"
  
  
// Connect to the database and build the <item> tags
  
$svrConn = @mysql_connect($dbServer$dbUser$dbPass) or die("Couldn't connect to database");
  
$dbConn = @mysql_select_db($dbName$svrConn) or die("Couldn't select database");
  
  
// Make sure the table exists
  
$tableExists false;
  
$tResult mysql_list_tables($dbName);
  
  while(
$tRow mysql_fetch_row($tResult))
  {
  if(
strtolower($tableName) == strtolower($tRow[0]))
  {
  
$tableExists true;
  break;
  }
  }
  
  if(!
$tableExists)
  die(
"Table $tableName doesn't exist in the database!");
  }
  {
 
$rResult mysql_query("select $titleFieldName, $descFieldName, $linkFieldName from $tableName order by $linkFieldName asc limit 15") or die("An error occured while retrieving records: " mysql_error()); 
  
  
// The records were retrieved OK, let's start building the item tags
  
while($rRow mysql_fetch_array($rResult))
  {
  
$rssValue .= "<item>\r\n";
  
$rssValue .= "<title>" htmlspecialchars($rRow[$titleFieldName], ENT_QUOTES) . "</title>\r\n";
  
$rssValue .= "<description>" htmlspecialchars($rRow[$descFieldName], ENT_QUOTES) . "</description>\r\n";
  
$rssValue .= "<link>" str_replace("{diningID}"$rRow[$linkFieldName], $linkTemplate) . "</link>\r\n";
  
$rssValue .= "</item>\r\n";
  } 
  
  
// Add the closing rss tag and return the value
  
$rssValue .= "</rss>\r\n";
  return 
$rssValue
  }
  
?>


I don't understand why I'm getting an error, probably because I don't fully understand everything that's going on in both of these pages.

Could somebody please help me figure out why this isn't working?

Thank you all so much.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingProgramming Tools > Article Discussion: Building a Generic RSS Class With PHP


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump