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 :)

[cc lang=”php”]

# 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(“&lt;”, “<“, $tweet);
$tweet = str_replace(“&gt;”, “>”, $tweet);
$tweet = str_replace(“&quot;”, “”, $tweet);
return $tweet;
}
# Parsed and echo to the screen.
$twitterFeed = file_get_contents($feed);
echo parse_feed($twitterFeed) . stripslashes($suffix);

[/cc]

Its that simple, enjoy! xD!

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

Published by

Miguel

I’m a bilingual Network Engineer. I have over 20 Years of Professional experience in Computer Science & Information Technology. I currently own and operate Web Semantics (www.websemantics.com) in Vancouver, Washington. I provide bilingual (English & Spanish) enterprise-level IT support to small and medium-sized businesses across the West Coast. *** Soy un ingeniero de redes bilingüe. Tengo más de 20 años de experiencia profesional en ciencias de la computación y tecnología de la información. Actualmente poseo y opero Web Semantics (www.websemantics.com) en Vancouver, Washington. Proporciono soporte de IT/Informática bilingüe (inglés y español) a nivel empresarial a pequeñas y medianas empresas en toda la costa oeste.

Leave a Reply