merylvingien Posted May 24, 2012 Share Posted May 24, 2012 Hi Folks, i have added a twitter function to one of the pages on my site, thought it was working ok, but getting a few error messages in the logs. The function i am using is this: function getTwitterStatus($userid){ $url = "http://twitter.com/statuses/user_timeline/$userid.xml?count=5"; $file_headers = get_headers($url); if($file_headers[0] == 'HTTP/1.0 400 Bad Request') { echo "Sorry we cannot retrieve these tweets"; } else { $xml = simplexml_load_file($url); foreach($xml->status as $status){ $text = $status->text; $text = preg_replace( "/((http|ftp)+(s)?:\/\/[^<>\s]+)/i", "<a href=\"\\0\" target=\"_blank\">\\0</a>",$text); $text = preg_replace('/(^|\s)@(\w+)/', '\1@<a href="http://www.twitter.com/#!/\2">\2</a>', $text); $text = preg_replace('/(^|\s)#(\w+)/', '\1#<a href="http://search.twitter.com/search?q=%23\2">\2</a>', $text); echo "<div class=\"tweet\">$text</div>"; } } } The errors are intermittent, but show up like this: PHP Warning: simplexml_load_file() [<a href='function.simplexml-load-file'>function.simplexml-load-file</a>]: http://twitter.com/statuses/user_timeline/edited-username.xml?count=5:1: parser error : Start tag expected, '<' not found in /home/site/public_html/phppage.php on line 14 Line 14 is: $xml = simplexml_load_file($url); Any ideas? Link to comment https://forums.phpfreaks.com/topic/263060-getting-tweets/ Share on other sites More sharing options...
Psycho Posted May 24, 2012 Share Posted May 24, 2012 The output from $url is not in a valid XML format. You would have to log/record what WAS returned from that URL to see what the problem is. Could be the page was down or took to long to respond. Link to comment https://forums.phpfreaks.com/topic/263060-getting-tweets/#findComment-1348326 Share on other sites More sharing options...
merylvingien Posted May 24, 2012 Author Share Posted May 24, 2012 Its possible that twitter didnt respond i suppose. I will look into the url and see if i can find a suitable solution. Thanks for the reply Link to comment https://forums.phpfreaks.com/topic/263060-getting-tweets/#findComment-1348327 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.