Jump to content

Getting tweets


merylvingien

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.