You are here:  » problem with one feed-others ok


problem with one feed-others ok

Submitted by saschamcdonald on Sun, 2009-09-06 18:10 in

Hi,

The following code was generated by the Demo and worked fine in the demo. However, it fails to work on my server.
I am able to download various other feeds beautifully- nice work. However, the feed below just returns a blank page.
I am confused as to why other feeds work and this particular one does not.
Any ideas please?

<?php
  
require("MagicParser.php");
  function 
myRecordHandler($record)
  {
    
// This is where you write your code to process each record, such as loading a database
    // You can display the record contents using PHP's internal print_r() function:
    
print_r($record);
    
// The following code will print out each field in your sample data:
    
print $record["ITEM"];
    print 
$record["TITLE"];
    print 
$record["LINK"];
    print 
$record["DESCRIPTION"];
    print 
$record["GUID"];
    print 
$record["PUBDATE"];
  }
  
MagicParser_parse("{link saved}","myRecordHandler","xml|RSS/CHANNEL/ITEM/");
?>

Submitted by support on Sun, 2009-09-06 18:21

Hello Sascha,

The link was retrieved fine from my test server, as I wondered if it might be a user-agent issue (some servers won't return data to a PHP script for example, so it's necessary to over-ride the user-agent with ini_set but that doesn't appear to be the case here).

I presume that other URLs are working, so there is no problem retrieving URLs via PHP on your server.

Either way, it may be worth trying CURL as an alternative if it is compiled into your PHP installation. To do this, in place of the following line:

  MagicParser_parse("{link saved}","myRecordHandler","xml|RSS/CHANNEL/ITEM/");

...use the following code:

  $ch = curl_init("{link saved}");
  curl_setopt($ch,CURLOPT_HEADER,0);
  curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
  $xml = curl_exec($ch);
  MagicParser_parse("string://".$xml,"myRecordHandler","xml|RSS/CHANNEL/ITEM/");

(replacing {link saved} with your URL of course)

Hope this helps!
Cheers,
David.

Submitted by saschamcdonald on Tue, 2009-09-08 21:51

Hi David,

Thanks very much for this idea. However, I ended up using the following to test the data returned. It displayed a redirection page with a link and no XML. I discovered that this was because my server is in the US. The host site was redirecting my UK feed to a different, regionally based server via a transition page with a link

<?php
file_get_contents
("{link_to_rss}");
echo
"$html";
?>

Cheers and Beers,

Sascha