내 웹 사이트에 RSS 피드를 포함하려고합니다. 다음 코드는 로컬로 작동하지만 라이브 사이트에 치명적인 오류가 발생합니다 : 내가 찾은 시행 착오 및 이와 유사한 질문을 찾는 많은 후PHP 치명적 오류 : 문자열을 XML로 구문 분석 할 수 없습니다.
[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->__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
: 이것은 다음과 같은 오류가 발생
<?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 '<ul>' . "\n";
for($i=0; $i<5; $i++) {
$url = $doc->channel->item[$i]->link;
$title = $doc->channel->item[$i]->title;
$date = $doc->channel->item[$i]->pubDate;
echo '<li>' . "\n";
echo '<a href="'.$url.'">'.$title.'</a>' . "\n";
echo '</li>' . "\n";
}
echo '</ul>' . "\n";
}
?>
<!doctype html>
<html lang="en-GB">
<head>
<meta charset="UTF-8" />
<title>Test feed</title>
</head>
<body>
<h2>Recent blog entries</h2>
<?php parseRSS($doc); ?>
</body>
</html>
문제를 일으키는 피드입니다. 피드를 매우 기본적인 샘플 느낌 (예 : http://feedparser.org/docs/examples/rss20.xml)으로 변경하면 모두 정상적으로 작동합니다. 구문 분석하려는 피드가 유효합니다 (경고가 있지만).
질문입니다 ... 스크립트를 피드를 받아들이려면 어떻게해야합니까?
피드에 영향을 줍니까? 당신은 그것을 유효하게 할 수있다;) – TJHeuvel