Display and Format Latest Tweet

Wrap this in a div.

<?php // Your twitter username.
    $username = "dauidus";

    // PREFIX (HTML is OK, but be sure to escape quotes with backslashes: for example href=\"link.html\")
    $prefix = " &nbsp; &nbsp; ";

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

    $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);
	    $tweet = str_replace("&amp;", "&", $tweet);
	    $tweet = str_replace("@", "<span class='redtext'>@</span>", $tweet);
	    $tweet = str_replace("<br>", "&nbsp;", $tweet);
	    $tweet = str_replace("</br>", "&nbsp;", $tweet);
	        return $tweet;
	}   

	$twitterFeed = file_get_contents($feed);                       
    echo stripslashes($prefix) . parse_feed($twitterFeed) . stripslashes($suffix);
?>

 

Dave Winter focuses in WordPress UI Design and WordPress Plugin Development (some have labelled him a fanatic) but has hands in many other projects, including photography and music. He's never far from a computer... or an iPad (for testing purposes, of course). If you've been to a WordCamp in Southern California, he probably already knows who you are (or maybe not - he's terrible with names). Dave currently teaches courses at California State University, Long Beach alongside his small business at dauid.us (and his students think he's pretty boss).
© 2008-2020, dauid.us