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

5
  • Check your PHP error log for any errors. Commented Apr 16, 2013 at 14:28
  • Your code works fine here: codepad.viper-7.com/uAqFCk Commented Apr 16, 2013 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 :-) Commented Apr 16, 2013 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. Commented Apr 16, 2013 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. Commented Apr 16, 2013 at 14:41

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

1 Comment

thank you, ill have my friend give fasthosts a kick. thanks for sanity checking it for me all

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.