0
我正在下載一些RSS格式的博客。這是一個例子:php - 如何解析博客rss文件
<rss xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
<channel>
<title>
john doe clippingsconverter - Google Blog Search
</title>
<link>
http://www.google.com/search?hl=en&q=john+doe+clippingsconverter&tbm=blg
</link>
<description>1 result</description>
<opensearch:totalResults>1</opensearch:totalResults>
<opensearch:startIndex>1</opensearch:startIndex>
<opensearch:itemsPerPage>1</opensearch:itemsPerPage>
<item>
<title>5 Best Kindle Tips and Tricks - Make Tech Easier</title>
<link>
http://www.maketecheasier.com/5-best-kindle-tips-and-tricks/2010/10/16
</link>
<description>
<em>John Doe</em>. You can convert your clippings file to word, excel and pdf at http://www.<em>clippingsconverter</em>.com · 28th April 2011 02:53:00 Reply. Anonymous. yes, http://www.<em>clippingsconverter</em>…. is a true gem. I also use this <b>...</b>
</description>
<dc:publisher>Make Tech Easier</dc:publisher>
<dc:creator>Abhiroop Basu</dc:creator>
<dc:date>Sat, 16 Oct 2010 12:00:53 GMT</dc:date>
</item>
</channel>
</rss>
我使用這個代碼:
$feed = file_get_contents($SearchURL);
$xml = new SimpleXmlElement($feed);
foreach ($xml->channel->item as $entry){
echo $entry->title;
echo $entry->description;
}
我收到此錯誤信息:
Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: Entity: line 21: parser error : Input is not proper UTF-8, indicate encoding !
我發現下載的飼料確實不這行在頂部,這可能會解釋錯誤。
<?xml version="1.0" encoding="UTF-8"?>
感謝您的幫助。
完美。感謝Srikanth – Jeremy