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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.