Discussion board
Error reading RSS feed
27-11-2009 22:30:25
Chakalaka
First, let me thank the author of the RSS reading textbook for doing a good job (simple and accurate tuto). I tried to use code to read an RSS feed from a new site. I have the following error: Notice: Trying to get property of non-object in C :\....\flowRSS on line 30 This famous line $ description = $ tnl-> firstChild-> data; I checked in my .xml, I have a description of the tag, Qlq1 will be an idea how to solve this error? Another question: How to limit showing (or reading) only the 3 first news of the RSS channel? Finally: I can't figure out what the following lines of code are doing
$tnl = $item->getElementsByTagName("description"); $tnl = $tnl->item(0); $description = $tnl->firstChild->data;Small detail (last swear) On my fury I have the next display
Golfer Tiger Woods was welcoming Friday after...Is there a way to show the symbols correctly? Here's my PHP code:
<link rel="alternate" type="application/rss+xml" title="Nouvelles" href="http://www.cyberpresse.ca/rss/178.xml" /> echo RSS_Display("http://www.cyberpresse.ca/rss/178.xml", 15);Merci pour vos réponses :)
29-11-2009 20:47:20
webmaster
I tried to use code to read an RSS feed from a new site. I have the following error: Notice: Trying to get property of non-object in C :\....\flowRSS .php on line 30 This famous line is $ description = $ tnl -> firstChild-> data; [/quote There may be a compatibility issue. Try using textContent instead of data. Another question: How to limit showing (or reading) only the 3 first news of the RSS channel?Edit this line:
$recents = array_slice($RSS_Content, 0, $size);
$recents = array_slice($RSS_Content, 1, 3);You start with 0 or 1 depending on whether you want to show the site name. You can also call the RSS_Display ($ url, $ size) function with a value of 3 for the $ size parameter.
Can't figure out what the following lines of code are doing$ tnl is a NodeList DOM object. It contains a list of items. $ tnl-> item (0) and first in the list. $ tnl -> firstChild is the first element contained in this clause. and data, now replaced by textContent is the text contained in the tag. All this is used to get the content of the description tag in the stream.$tnl = $item->getElementsByTagName("description"); $tnl = $tnl->item(0); $description = $tnl->firstChild->data;
My fury bears the following poster: "Goalkeeper Tiger Woods on Friday after he... Is there a way to show the symbols correctly?Problem with Doctype. The XML file is located in UTF-8, the page on which it is displayed must also be in UTF-8. When on a page used to create a stream, if it is not in UTF-8, the PHP transform function is used: utf8_encode
$description = utf8_encode($tnl->firstChild->textContent;)
03-12-2009 05:03:57
Chakalaka
Endless thanks;)
25-05-2010 15:25:44
Scorleon
Hello, I downloaded the 2010 version and really big bravo, it works well. Thank you Except that I have the same strange character mapping error even after I forcibly encoded utf8_encode for description. For example, I am testing with a newspaper stream the world: http://www.lemonde.fr/rss/sequence/0, 2-3208.1-0.0.xml Do you have a solution? Thanks
25-05-2010 20:14:16
webmaster
Hello, I tested the feed with a demo script: https://www.iqlevsha.ru/rss/rss-simple.php This displays normally. The script uses UTF-8 encoding, so the problem should arise due to the page encoding.
25-05-2010 22:52:23
scorleon1
Hi, Thanks for the quick response and dsl I created a new account because the old one no longer works even after password initialization. Well, I redid everything to zero, but I have the following error: fatal error: Call to undefined method: domdocument-> load () in/homepages/17/d329985513/html/rsslib/rsslib.php on line 77 on this line:
$doc->load($url);My site is hosted at 1and1 . Thank you for all of your help.
26-05-2010 19:39:19
webmaster
This is what usually happens when PHP is not in version 5. Even if the hosting supports PHP 5, it can be configured with PHP 4 by default. Check the phpinfo () version.
<?php echo phpinfo(); ?>
26-05-2010 21:58:36
scorleon1
Here is the version of the php server: PHP Version 5.2.13 Now I have the following messages: Warning: DOMDocument:: load () [domdocument.load]: file-access URL disabled in server configuration in/homepages/17/d329985513/html/rsslib/rsslib.php on line 77 Warning: DOMDocument:: load (http://www.lemonde.fr/rss/sequence/0, 2-3208,1-0,0.xml) [domdocument.load]: failed to open stream: no suitable wrapper cound be found in/homepages/17/d329985513/html/rsslib/rsslib.php on линия 77 Варнинг: DOMDocument:: load () [domdocument.load]: I/O warning: failed to load external object "http://www.lemonde.fr/rss/sequence/0, 2-3208.1-0.0.xml" in/homepages/17/d329985513/html/rsslib/rsslib.php on line 77
27-05-2010 19:08:43
webmaster
The message indicates that the server configuration does not allow the file to be downloaded as a URL. The allow_url_fopen variable is disabled. Never facing this problem, I suppose it is specific to 1and1. Do you have access to PHP customization? You can also try replacing in RSS_retrieve
$doc = new DOMDocument(); $doc->load($url);
$data = file_get_contents($url); $doc = new DOMDocument(); $doc->loadXML(data);
27-05-2010 21:35:50
scorleon1
Hi, I tried but it doesn't work, always the same mistakes. otherwise I found it:" http://faq.1and1.fr/scripts/php/11.html "I tried, but it is not yet activated, I think it takes time. Otherwise, I found a solution (always your code), but I have problems with characters: I replace this code:
global $RSS_Content; $doc = new DOMDocument(); $doc->load($url); $channels = $doc->getElementsByTagName("channel"); $RSS_Content = array(); foreach($channels as $channel) { RSS_Channel($channel); }by this:
global $RSS_Content; $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); curl_setopt($ch, CURLOPT_URL, $url); $result = curl_exec($ch); curl_close($ch); $doc = new DOMDocument(); $doc->loadXML($result); $channels = $doc->getElementsByTagName("channel"); $RSS_Content = array(); foreach($channels as $channel) { RSS_Channel($channel); }
28-05-2010 14:27:31
webmaster
Why don't you use fsockopen?
$fp = fsockopen("www.example.com/rss.xml", 80, $errno, $errstr, 30); $data = ""; while (!feof($fp)) { $data .= fgets($fp, 128); } fclose($fp); $doc = new DOMDocument(); $doc->loadXML($data);Following the example of a PHP textbook adapted to the situation.
29-05-2010 01:18:37
scorleon1
I had an endless loop: D
29-05-2010 20:40:33
webmaster
I just tested the following code in conjunction with the rss-reg.php demo:
$doc = new DOMDocument(); /* $doc->load($url); */ $fp = fsockopen($url); $data = ""; while (!feof($fp)) { $data .= fgets($fp, 128); } fclose($fp); $doc = new DOMDocument(); $doc->loadXML($data);It works perfectly and the flow has appeared. Do you have the opportunity to test the script on another hoster?
30-05-2010 00:28:29
scorleon1
Yes, I am testing for 1and1 and ovh. But this does not work with the latest code either, its fact is shot down by IE and firefox and chrome. But, as I said, it works well with this code, except for specification characters that do not appear :
global $RSS_Content; $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); curl_setopt($ch, CURLOPT_URL, $url); $result = curl_exec($ch); curl_close($ch); $doc = new DOMDocument(); $doc->loadXML($result); $channels = $doc->getElementsByTagName("channel"); $RSS_Content = array(); foreach($channels as $channel) { RSS_Channel($channel); }
31-05-2010 14:17:08
webmaster
Hello, I tried your exact code with rss-direct.php and it works great, no problem with special characters. This should be a page format or browser customization issue. rss-direct.php header:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" dir="ltr" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
02-06-2010 22:13:24
scorleon1
Hello, this is the same config that I have on the page. I don't know why it doesn't work.
03-06-2010 10:20:24
webmaster
If I had a link to a page or demo page (no http ://due to anti-spam filter).
09-06-2010 23:01:53
scorleon1
Hello Dsl, I have been on the road, I will try to do this weekend and give you a link.