我正在使用名爲SimplePie的非常酷的php庫(不管它叫什麼)。我正在使用最新版本。SimplePie獲取無效的XML文檔
我有這樣的代碼:
$url = 'http://www.seobook.com/feeds.shtml';
$SimplePieFeed->set_feed_url($url);
$SimplePieFeed->force_feed(true);
$SimplePieFeed->enable_order_by_date(true);
$success = $SimplePieFeed->init();
if(!$SimplePieFeed->error()) {
foreach($SimplePieFeed->get_items() as $item) {
......
}
} else {
print_r($SimplePieFeed->error());
}
爲什麼當我運行此代碼,我得到這樣那樣的錯誤:
This XML document is invalid, likely due to invalid characters. XML error: not well-formed (invalid token) at line 8, column 76
我嘗試運行這一項上Simplepie's demo和一切進行得都很順利。爲什麼當我運行它時,我有這種錯誤?是否因爲緩存?我注意到Simplepie將提要存儲在緩存中。我試過$SimplePieFeed->enable_cache(false);
但我仍然得到這個錯誤。我甚至不確定這是否與這種錯誤有關。大聲笑!
您的幫助將不勝感激和獎勵! :非常感謝你!
不同的網站使用不同的請求標頭。如果你不想比較所有這些,第一步是獲取* actual * feed URL:http://www.seobook.com/rss.xml - 至少XML驗證那麼:http:// validator .w3.org/appc/check.cgi?url = http%3A%2F%2Fwww.seobook.com%2Frss.xml – hakre
@hakre這是一個用戶輸入,你有任何想法如何確保用戶輸入了一個實際的供稿網址? – PinoyStackOverflower
那麼,如果你無法與用戶溝通你需要什麼,那你就註定了。至少對於簡單的輸入處理。如果用戶太愚蠢,用戶太愚蠢。檢查simplepie演示應用程序會發生什麼,如果可以,請檢查請求。他們可能在他們的網站上有它的來源。 – hakre