title: PHP Fatal error: String could not be parsed as XML
body: <p>I'm trying to include an RSS feed on my website. The following code works locally but causes a fatal error on the live site:</p>
  
  <pre><code>&lt;?php
  // Initialise the cURL resource handle:
  $ch = curl_init("http://www.blogs.stopjunkmail.org.uk/diary/index.php?/feeds/index.rss2");
  // Set connection options:
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_HEADER, 0);
  // Execute connection, wait for response, and close:
  $data = curl_exec($ch);
  curl_close($ch);
  // Parse the data:
  $doc = new SimpleXmlElement($data, LIBXML_NOCDATA);
  // Define the function to parse RSS:
  function parseRSS($doc) {
      echo '&lt;ul&gt;' . "\n";
      for($i=0; $i&lt;5; $i++) {
          $url    = $doc-&gt;channel-&gt;item[$i]-&gt;link;
          $title  = $doc-&gt;channel-&gt;item[$i]-&gt;title;
          $date   = $doc-&gt;channel-&gt;item[$i]-&gt;pubDate;
          echo '&lt;li&gt;' . "\n";
          echo '&lt;a href="'.$url.'"&gt;'.$title.'&lt;/a&gt;' . "\n";
          echo '&lt;/li&gt;' . "\n";
      }
      echo '&lt;/ul&gt;' . "\n";
  }
  ?&gt;
  &lt;!doctype html&gt;
  &lt;html lang="en-GB"&gt;
  &lt;head&gt;
   &lt;meta charset="UTF-8" /&gt;
   &lt;title&gt;Test feed&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
   &lt;h2&gt;Recent blog entries&lt;/h2&gt;
  &lt;?php parseRSS($doc); ?&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>This causes the following errors:</p>
  
  <pre><code>[Thu Sep 29 12:06:28 2011] [error] [client xx.xx.xx.xxx] PHP Fatal error:  Uncaught exception 'Exception' with message 'String could not be parsed as XML' in /home/sites/stopjunkmail.org.uk/public_html/news/_test.php:11
  [Thu Sep 29 12:06:28 2011] [error] [client xx.xx.xx.xxx] Stack trace:
  [Thu Sep 29 12:06:28 2011] [error] [client xx.xx.xx.xxx] #0 /home/sites/stopjunkmail.org.uk/public_html/news/_test.php(11): SimpleXMLElement-&gt;__construct('', 16384)
  [Thu Sep 29 12:06:28 2011] [error] [client xx.xx.xx.xxx] #1 {main}
  [Thu Sep 29 12:06:28 2011] [error] [client xx.xx.xx.xxx]   thrown in /home/sites/stopjunkmail.org.uk/public_html/news/_test.php on line 11
  </code></pre>
  
  <p>After lots of trial and error and looking up similar questions I've found it's the feed that's causing the problem. If I change the feed to a very basic sample feel (for instance <a href="http://feedparser.org/docs/examples/rss20.xml" rel="nofollow">http://feedparser.org/docs/examples/rss20.xml</a>) it all works fine. The feed I'm trying to parse is valid (though has some warnings).</p>
  
  <p>Question is... what do I need to do get the script to accept the feed? </p>