While Retrieve The Searched tweet to My Application i got an Parser Error


#1

While Retrieve The Searched tweet to My Application i got an Parser Error string could not be parsed as xml simplexmlelement…

Code Is :

<?php $xmldata = 'https://api.twitter.com/1/statuses/user_timeline.xml?include_entities=true&include_rts=true&screen_name=cloudmagic&count=2'; $open = fopen($xmldata, 'r'); $content = stream_get_contents($open,-1); fclose($open); $xml = new SimpleXMLElement($content); ?>
<? echo $xml->status[0]->text ?>

error :

Fatal error: Uncaught exception ‘Exception’ with message ‘String could not be parsed as XML’ in C:\wamp\www\new\Untitled-11.php:7 Stack trace: #0 C:\wamp\www\new\Untitled-11.php(7): SimpleXMLElement->__construct(’’) #1 {main} thrown in C:\wamp\www\new\Untitled-11.php on line 7


#2

Certain flavors of errors on the API can return error documents in formats you may not be expecting. It would be wise to verify that you have XML content before trying to parse the XML. You also may want to add exception handling based on the HTTP status code you get in response to your requests – they won’t always be successful.


#3