xml - php - how to parse a blog rss file -


i downloading blogs in rss format. example:

<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 , 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>. can convert clippings file word, excel , pdf @  http://www.<em>clippingsconverter</em>.com &middot; 28th april 2011 02:53:00 reply. anonymous. yes, http://www.<em>clippingsconverter</em>…. true gem. use this&nbsp;<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> 

i using code:

$feed = file_get_contents($searchurl); $xml = new simplexmlelement($feed);  foreach ($xml->channel->item $entry){   echo $entry->title;   echo $entry->description; } 

i error message:

warning: simplexmlelement::__construct() [simplexmlelement.--construct]: entity: line 21: parser error : input not proper utf-8, indicate encoding !  

i notice feed downloaded not have line @ top, might explain error.

<?xml version="1.0" encoding="utf-8"?> 

thanks help.

check using utf8_encode

$feed = utf8_encode(file_get_contents($searchurl)); 

Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -