Forum Moderators: coopster

Message Too Old, No Replies

Simplepie RSS with Joomla

         

mightymouse3062

8:19 pm on Sep 9, 2010 (gmt 0)

10+ Year Member



Good Afternoon,
I am having some trouble with getting an RSS feed to work in Joomla and I have not found any help for it.

The site is [gta-nation.com...]

Here are the errors that I am getting (they repeat so its somewhere in a loop):
Warning: preg_match() [function.preg-match]: Compilation failed: nothing to repeat at offset 551 in /home2/gtanatio/public_html/terrazza2/libraries/simplepie/simplepie.php on line 13264

Warning: preg_match() [function.preg-match]: Compilation failed: nothing to repeat at offset 497 in /home2/gtanatio/public_html/terrazza2/libraries/simplepie/simplepie.php on line 13352

Warning: preg_match() [function.preg-match]: Compilation failed: nothing to repeat at offset 497 in /home2/gtanatio/public_html/terrazza2/libraries/simplepie/simplepie.php on line 13418


Here are lines 13249 - 13265:
if (!$pcre)
{
$wsp = '[\x09\x20]';
$fws = '(?:' . $wsp . '+|' . $wsp . '*(?:\x0D\x0A' . $wsp . '+)+)';
$optional_fws = $fws . '?';
$day_name = $this->day_pcre;
$month = $this->month_pcre;
$day = '([0-9]{1,2})';
$hour = $minute = $second = '([0-9]{2})';
$year = '([0-9]{2,4})';
$num_zone = '([+\-])([0-9]{2})([0-9]{2})';
$character_zone = '([A-Z]{1,5})';
$zone = '(?:' . $num_zone . '|' . $character_zone . ')';
$pcre = '/(?:' . $optional_fws . $day_name . $optional_fws . ',)?' . $optional_fws . $day . $fws . $month . $fws . $year . $fws . $hour . $optional_fws . ':' . $optional_fws . $minute . '(?:' . $optional_fws . ':' . $optional_fws . $second . ')?' . $fws . $zone . '/i';
}
if (preg_match($pcre, $this->remove_rfc2822_comments($date), $match))
{


Here are lines 13341 - 13343:
static $pcre;
if (!$pcre)
{
$space = '[\x09\x20]+';
$day_name = $this->day_pcre;
$month = $this->month_pcre;
$day = '([0-9]{1,2})';
$year = $hour = $minute = $second = '([0-9]{2})';
$zone = '([A-Z]{1,5})';
$pcre = '/^' . $day_name . ',' . $space . $day . '-' . $month . '-' . $year . $space . $hour . ':' . $minute . ':' . $second . $space . $zone . '$/i';
}
if (preg_match($pcre, $date, $match))
{


Here are lines 13406 - 13419:
static $pcre;
if (!$pcre)
{
$space = '[\x09\x20]+';
$wday_name = $this->day_pcre;
$mon_name = $this->month_pcre;
$day = '([0-9]{1,2})';
$hour = $sec = $min = '([0-9]{2})';
$year = '([0-9]{4})';
$terminator = '\x0A?\x00?';
$pcre = '/^' . $wday_name . $space . $mon_name . $space . $day . $space . $hour . ':' . $min . ':' . $sec . $space . $year . $terminator . '$/i';
}
if (preg_match($pcre, $date, $match))
{


The problem is with the preg_match() function however I do not know what is going on with it. I am running Joomla 1.5.20, PHP version 5.2.6. I am trying to use this RSS Feed: [news.google.com...]

Any help would be greatly appreciated.

Thanks,
Mike

astupidname

8:29 am on Sep 11, 2010 (gmt 0)

10+ Year Member



I'm not sure why the trouble, and I've only briefly looked at simplepie (and found myself unhappy with it -for something called 'simple' it sure is huge and overdone when I can usually get what I want done with far less code than it uses [382Kb+? geez]... plus I had some other problems with it too).
Consider this as what a typical starting point may be:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>google news feed</title>
</head>
<body>
<div>

<?php
//>

define('NL', "\r\n"); //defining line feeds for code formatting

$feedUrl = 'http://news.google.com/news?pz=1&cf=all&ned=us&hl=en&geo=chester+county+pa&output=rss';
$xml = @simplexml_load_file($feedUrl); //just in case, suppress error messages by using the '@'
if ($xml !== false) {
$channel = $xml->channel; //the 'channel' element of the rss feed
echo '<h3>'.$channel->title.'</h3>'.NL; //the channel's 'title' element's nodeValue
$items = $channel->item; //an array (because there's more than one of the 'item' elements,
//else it would be a SimpleXMLElement object) of all the rss 'channel' element's 'item' elements as SimpleXMLElement object's
foreach ($items as $item) { //
//echo '<p><a href="'.$item->link.'">'.$item->title.'</a></p>'.NL;
echo $item->description.NL;
}
}

?>

</div>
</body>
</html>


Look in to php's SimpleXML (scroll down a bit): [php.net...] or ask more here if you need help further parsing the feed.
Also, in the document above, note the meta-content-type tag as utf-8 charset as the feed does contain some utf-8 characters.

If anybody's wondering, how to post formatted code on webmasterworld [webmasterworld.com]
Do not copy formatted code on webmasterworld from IE, use other browser such as Firefox.

mightymouse3062

9:05 pm on Sep 13, 2010 (gmt 0)

10+ Year Member



Good Afternoon,
I have to agree with you that simplepie ain't really simple.

In looking at your code I understand what is going on with it. The problem I am having is it will not display anything on the page. When I get rid of the @ to suppress errors, I have the following appear:

Warning: simplexml_load_file() [function.simplexml-load-file]: http://news.google.com/news?pz=1&cf=all&ned=us&hl=en&geo=chester+county+pa&output=rss:20: parser error : Opening and ending tag mismatch: meta line 4 and head in /home2/gtanatio/public_html/pcre/rss.php on line 16

Warning: simplexml_load_file() [function.simplexml-load-file]: </head> in /home2/gtanatio/public_html/pcre/rss.php on line 16

Warning: simplexml_load_file() [function.simplexml-load-file]: ^ in /home2/gtanatio/public_html/pcre/rss.php on line 16

Warning: simplexml_load_file() [function.simplexml-load-file]: http://news.google.com/news?pz=1&cf=all&ned=us&hl=en&geo=chester+county+pa&output=rss:21: parser error : AttValue: " or ' expected in /home2/gtanatio/public_html/pcre/rss.php on line 16

Warning: simplexml_load_file() [function.simplexml-load-file]: <body text=#000000 bgcolor=#ffffff> in /home2/gtanatio/public_html/pcre/rss.php on line 16

Warning: simplexml_load_file() [function.simplexml-load-file]: ^ in /home2/gtanatio/public_html/pcre/rss.php on line 16

Warning: simplexml_load_file() [function.simplexml-load-file]: http://news.google.com/news?pz=1&cf=all&ned=us&hl=en&geo=chester+county+pa&output=rss:21: parser error : attributes construct error in /home2/gtanatio/public_html/pcre/rss.php on line 16

Warning: simplexml_load_file() [function.simplexml-load-file]: <body text=#000000 bgcolor=#ffffff> in /home2/gtanatio/public_html/pcre/rss.php on line 16

Warning: simplexml_load_file() [function.simplexml-load-file]: ^ in /home2/gtanatio/public_html/pcre/rss.php on line 16

Warning: simplexml_load_file() [function.simplexml-load-file]: http://news.google.com/news?pz=1&cf=all&ned=us&hl=en&geo=chester+county+pa&output=rss:21: parser error : Couldn't find end of Start Tag body line 21 in /home2/gtanatio/public_html/pcre/rss.php on line 16

Warning: simplexml_load_file() [function.simplexml-load-file]: <body text=#000000 bgcolor=#ffffff> in /home2/gtanatio/public_html/pcre/rss.php on line 16

Warning: simplexml_load_file() [function.simplexml-load-file]: ^ in /home2/gtanatio/public_html/pcre/rss.php on line 16


I do not know what they all mean, can you help me out with that?

Thanks,
Mike

astupidname

5:56 am on Sep 14, 2010 (gmt 0)

10+ Year Member



The example I posted, if I copy and paste it verbatim I have no such troubles even if I remove the '@'. The error messages are basically telling us that the xml file (rss feed) was not a well formed xml document. In fact, from the Warning's it appears google may have served you a regular (though maybe malformed in it's self) html file (thus the references to head and body tags in the Warning's) at that time, perhaps there was a temporary 'outage' of the feed? Don't know what to say other than that, right now the feed appears well formed and working fine. Perhaps if you are still having trouble, are you using exactly as in the example? If not, perhaps show any variations you have made.