11 08 2015

28. 从任意的 Twitter 账号获取最新的 Tweet 

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
function my_twitter($username)
{
     $no_of_tweets = 1;
     $feed = "http://search.twitter.com/search.atom?q=from:" . $username . "&rpp=" . $no_of_tweets;
     $xml = simplexml_load_file($feed);
    foreach($xml->children() as $child) {
        foreach ($child as $value) {
            if($value->getName() == "link") $link = $value['href'];
            if($value->getName() == "content") {
                $content = $value . "";
        echo '<p class="twit">'.$content.' <a class="twt" href="'.$link.'" title="">&nbsp; </a></p>';
            }    
        }
    }    
}

语法:

?
1
2
3
4
<?php
$handle = "koonktech";
my_twitter($handle);
?>
发表评论