lunedì 14 febbraio 2011

READ LAST TWITTER POST

<?php
function parse_feed($usernames, $limit=1) {
    $usernames = str_replace("www.", "", $usernames);
    $usernames = str_replace("http://twitter.com/", "", $usernames);
        $username_for_feed = str_replace(" ", "+OR+from%3A", $usernames);
    $feed = "http://api.twitter.com/1/statuses/user_timeline/".$username_for_feed.".atom?callback=?";
    $cache_rss = file_get_contents($feed);
    if (!$cache_rss) {
        // we didn't get anything back from twitter
        echo "<!-- ERROR: Twitter feed was blank! Using cache file. -->";
    }

    // clean up and output the twitter feed
    $feed = str_replace("&amp;", "&", $cache_rss);
    $feed = str_replace("&lt;", "<", $feed);
    $feed = str_replace("&gt;", ">", $feed);
    $clean = explode("<entry>", $feed);
    $clean = str_replace("&quot;", "'", $clean);
    $clean = str_replace("&apos;", "'", $clean);
    $amount = count($clean) - 1;
    if($amount > $limit) $amount=$limit;
    $tweets = array();
    if ($amount) { // are there any tweets?
        for ($i = 1; $i <= $amount; $i++) {
            $entry_close = explode("</entry>", $clean[$i]);
            $clean_content_1 = explode("<content type=\"html\">", $entry_close[0]);
            $clean_content = explode("</content>", $clean_content_1[1]);
            $clean_name_2 = explode("<name>", $entry_close[0]);
            $clean_name_1 = explode("(", $clean_name_2[1]);
            $clean_name = explode(")</name>", $clean_name_1[1]);
            $clean_user = explode(" (", $clean_name_2[1]);
            $clean_lower_user = strtolower($clean_user[0]);
            $clean_uri_1 = explode("<uri>", $entry_close[0]);
            $clean_uri = explode("</uri>", $clean_uri_1[1]);
            $clean_time_1 = explode("<published>", $entry_close[0]);
            $clean_time = explode("</published>", $clean_time_1[1]);
            $unix_time = strtotime($clean_time[0]);
            $pretty_time = "";
            $tweets[] = array('content' => $clean_content[0], 'time' => $pretty_time);
        }
    }
    return $tweets;
}
$temp=parse_feed("237811224",1);
$temp2=$temp[0];

echo $temp2['content'];
?>

Nessun commento:

Posta un commento