此代碼完全適用於任何其他rss飼料,但不適用於谷歌新聞飼料。我不知道我在做什麼錯,我認爲這是一些錯誤。 當我嘗試閱讀谷歌新聞我不斷收到此錯誤飼料simplepie不解析谷歌新聞rss飼料
This XML document is invalid, likely due to invalid characters. XML error: SYSTEM or PUBLIC, the URI is missing at line 1, column 61
例如,如果我們嘗試http://stackoverflow.com/feeds
飼料它工作得很好,但不能與谷歌的新聞提要。有人能給我一個提示嗎?
<?php
//get the simplepie library
require_once('simplepie.inc');
//grab the feed
$feed = new SimplePie();
$feed->set_feed_url("http://news.google.com/news?hl=en&gl=us&q=austria&ie=UTF-8&output=rss");
$feed->force_feed(true);
//$feed->encode_instead_of_strip(true);
//enable caching
$feed->enable_cache(true);
//provide the caching folder
$feed->set_cache_location('cache');
//set the amount of seconds you want to cache the feed
$feed->set_cache_duration(1800);
//init the process
$feed->init();
//let simplepie handle the content type (atom, RSS...)
$feed->handle_content_type();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>simple</title>
</head>
<body>
<div id="page-wrap">
<h1>News Finder</h1>
<?php if ($feed->error): ?>
<p><?php echo $feed->error; ?></p>
<?php endif; ?>
<?php foreach ($feed->get_items() as $item): ?>
<div class="chunk">
<h4 style="background:url(<?php $feed = $item->get_feed(); echo $feed->get_favicon(); ?>) no-repeat; text-indent: 25px; margin: 0 0 10px;"><a href="<?php echo $item->get_permalink(); ?>"><?php echo $item->get_title(); ?></a></h4>
<p class="footnote">Source: <a href="<?php $feed = $item->get_feed(); echo $feed->get_permalink(); ?>"><?php $feed = $item->get_feed(); echo $feed->get_title(); ?></a> | <?php echo $item->get_date('j M Y | g:i a T'); ?></p>
</div>
<?php endforeach; ?>
</div>
我相信我發現了這個問題。這是我的託管公司[Rackspace]的問題。當我在另一家公司的另一個託管帳戶上嘗試它時,它的工作就像一個魅力。感謝@Ryan來幫忙。保重 – acrobat 2011-12-30 01:19:00
我面臨着幾乎相同的問題。你能告訴我你的主機問題到底是什麼嗎? – 2012-07-07 18:00:11
是的,請告訴我們您的主機有什麼問題? – PinoyStackOverflower 2012-11-22 06:40:18