Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 12-11-2010, 06:11 AM PHP Twitter Feed
pealo86's Avatar
Super Spam Talker

Posts: 876
Name: Matt Pealing
Location: England, north west
Trades: 0
Does anybody have any recommendations for PHP scripts to pull in a Twitter feed? I've tried several but each seem to just give me error messages!

I basically just need a PHP alternative so that the tweets can be read by search engines.

Thanks.
__________________

Please login or register to view this content. Registration is FREE
pealo86 is offline
Reply With Quote
View Public Profile Visit pealo86's homepage!
 
 
Register now for full access!
Old 12-11-2010, 08:42 AM Re: PHP Twitter Feed
pealo86's Avatar
Super Spam Talker

Posts: 876
Name: Matt Pealing
Location: England, north west
Trades: 0
Actually this one seems to work quite well:
PHP Code:
<?php
    $username 
"username";
    
$limit 5;
    
$feed 'http://twitter.com/statuses/user_timeline.rss?screen_name='.$username.'&count='.$limit;
    
$tweets file_get_contents($feed);        
        
$tweets str_replace("&""&"$tweets);    
        
$tweets str_replace("<""<"$tweets);
        
$tweets str_replace(">"">"$tweets);
        
$tweet explode("<item>"$tweets);
    
$tcount count($tweet) - 1;

for (
$i 1$i <= $tcount$i++) {
    
$endtweet explode("</item>"$tweet[$i]);
    
$title explode("<title>"$endtweet[0]);
    
$content explode("</title>"$title[1]);
        
$content[0] = str_replace("–""&mdash;"$content[0]);
        
$content[0] = preg_replace("/(http:\/\/|(www\.))(([^\s<]{4,68})[^\s<]*)/"'<a href="http://$2$3" target="_blank">$1$2$4</a>'$content[0]);
        
$content[0] = str_replace("$username: """$content[0]);
        
$content[0] = preg_replace("/@(\w+)/""<a href=\"http://www.twitter.com/\\1\" target=\"_blank\">@\\1</a>"$content[0]);
        
$content[0] = preg_replace("/#(\w+)/""<a href=\"http://search.twitter.com/search?q=\\1\" target=\"_blank\">#\\1</a>"$content[0]);
    
$mytweets[] = $content[0];
}

while (list(, 
$v) = each($mytweets)) {
    
$tweetout .= "<li>$v</li>";
}
?>
Only thing is, it doesn't output the date of the Tweets. I can see it is contained within the XML inside the '<pubdate>' elements, which are inside the '<item>' elements. But I cannot figure out how to retrieve it without messing up the for loop!

One thing that does confuse me is that the script looks for '<title>' elements, but when I set the script to pull in my tweets, there appears to be no XML element called '<title>' in there anywhere

Does anybody have any ideas?
__________________

Please login or register to view this content. Registration is FREE

Last edited by pealo86; 12-11-2010 at 08:44 AM..
pealo86 is offline
Reply With Quote
View Public Profile Visit pealo86's homepage!
 
Old 12-17-2010, 06:07 AM Re: PHP Twitter Feed
Skilled Talker

Posts: 50
Trades: 0
This can be done with javascript:

http://tweet.seaofclouds.com/
HullBorn is online now
Reply With Quote
View Public Profile
 
Old 12-17-2010, 06:14 AM Re: PHP Twitter Feed
Average Talker

Posts: 15
Name: Alex Rabe
Location: United States
Trades: 0
I thinks search engine bots will not ready the above code.
alexrabe is offline
Reply With Quote
View Public Profile Visit alexrabe's homepage!
 
Old 12-17-2010, 06:30 AM Re: PHP Twitter Feed
Super Spam Talker

Posts: 879
Name: Paul W
Trades: 0
title is set by the php: $title = explode("", $endtweet[0]);
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE


*** New:
Please login or register to view this content. Registration is FREE
PaulW is offline
Reply With Quote
View Public Profile
 
Old 12-19-2010, 08:25 AM Re: PHP Twitter Feed
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Quote:
none as simple as twitters
And that just about sums it up!!
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 12-20-2010, 07:33 AM Re: PHP Twitter Feed
joe12joe's Avatar
Banned

Posts: 12
Name: Joe
Location: Houston
Trades: 0
You can use this code as it works for me:

PHP Code:
<?php

// Your twitter username.
$username "TwitterUsername";

// Prefix - some text you want displayed before your latest tweet. 
// (HTML is OK, but be sure to escape quotes with backslashes: for example href=\"link.html\")
$prefix "";

// Suffix - some text you want display after your latest tweet. (Same rules as the prefix.)
$suffix "";

$feed "http://search.twitter.com/search.atom?q=from:" $username "&rpp=1";

function 
parse_feed($feed) {

$stepOne explode("<content type=\"html\">"$feed);
$stepTwo explode("</content>"$stepOne[1]);

$tweet $stepTwo[0];
$tweet str_replace("&lt;""<"$tweet);
$tweet str_replace("&gt;"">"$tweet);

return 
$tweet;

}

$twitterFeed file_get_contents($feed);

echo 
stripslashes($prefix) . parse_feed($twitterFeed) . stripslashes($suffix);

?>

Last edited by chrishirst; 12-20-2010 at 08:51 AM..
joe12joe is offline
Reply With Quote
View Public Profile Visit joe12joe's homepage!
 
Reply     « Reply to PHP Twitter Feed
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.51797 seconds with 12 queries