0

a while ago i did a quick news parser for a friend.

here is the code:

$ch = curl_init("http://feeds.energydigger.com/headlines.xml");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, 0);
$data = curl_exec($ch);
curl_close($ch);
$doc = new SimpleXmlElement($data, LIBXML_NOCDATA);

if(isset($doc->channel))
{
    parseRSS($doc);
}
function parseRSS($xml)
{
    $cnt = 3;
    for($i=0; $i<$cnt; $i++)
    {
    $url    = $xml->channel->item[$i]->link;
    $title  = $xml->channel->item[$i]->title;
    $desc = $xml->channel->item[$i]->description;
    $date = $xml->channel->item[$i]->pubDate;

    echo '<p><a href="'.$url.'">'.$title.'</a><br />'.$date.'</p>';
    }
}

this has been working perfect up till today and now i am getting a 500 server error on the page its trying to show the list.

Have i missed something obvious here or that anyone can spot easily

thanks in advance

PS i modified someones code i found a tutorial on

odd
  • 453
  • 2
  • 10
  • 21
  • Check your PHP error log for any errors. – Halcyon Apr 16 '13 at 14:28
  • Your code works fine here: http://codepad.viper-7.com/uAqFCk – Anyone Apr 16 '13 at 14:28
  • What _exact_ 500 error do you get? Besides this: "PS i modified someones code i found a tutorial on" - that's not a good thing, try something on your own and the search for errors is even easier :-) – akluth Apr 16 '13 at 14:29
  • A 500 status code (or a blank page) means that your script is throwing an error but you haven't configured PHP to display error messages. That's something you need to fix before you go further; it's impossible to code without the aid of error messages. Here's a [brief explanation](http://stackoverflow.com/a/5680885/13508). – Álvaro González Apr 16 '13 at 14:31
  • yes it works fine here too (locally that is) ill have a word with the hosts see if they can shed anymore light on the situation, good to know its find though code wise ill see what info i can get out of the hosts. – odd Apr 16 '13 at 14:41

1 Answers1

1

I just copy and pasted you code in a php page on my server and it works correctly.

I suspect your problem is curl installation. You probably get this error: Fatal error: Call to undefined function curl_init() on line 2 This is because you need to initialize curl extension.

Here is how to do it: http://nz.php.net/manual/en/curl.installation.php

This might also help:

Call to undefined function curl_init()

curl_init() function not working

Community
  • 1
  • 1
Hugo Rocha
  • 537
  • 5
  • 23
  • thank you, ill have my friend give fasthosts a kick. thanks for sanity checking it for me all – odd Apr 16 '13 at 14:55