Using PHP To Pull Your Last Tweet Via Twitters Atom Timeline

Ok here is a simple script that will help you pull your latest feed from your twitter atom rss timeline without the use of cURL :)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# Enter your twitter username
$username = "websymantecs";

#page title (if you want one >:P)
$prefix = "<h2>Tweet Tweet</h2>";

# Suffix - some text you want display after your latest tweet. (Same rules as the page title.)
$suffix = "";

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

# time to process our request
function parse_feed($feed) {
// time for our data parsing
$phase1 = explode("<content type="html">", $feed);
$phase2 = explode("</content>", $phase1[1]);
$tweet = $phase2[0];
$tweet = str_replace("<", "<", $tweet);
$tweet = str_replace(">", ">", $tweet);
$tweet = str_replace(""", "", $tweet);
return $tweet;
}
# Parsed and echo to the screen.
$twitterFeed = file_get_contents($feed);
echo parse_feed($twitterFeed) . stripslashes($suffix);

Its that simple, enjoy! xD!

After a successful feed, you can use CSS to style the returned data.

Comments

comments

Leave a Reply