19个超实用的PHP代码片段(6)

 
    public function loadTimeline($user, $max = 20){  
        $this->twitURL .= 'statuses/user_timeline.xml?screen_name='.$user.'&count='.$max;  
        $ch        = curl_init();  
        curl_setopt($ch, CURLOPT_URL, $this->twitURL);  
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);  
        $this->xml = curl_exec($ch);  
        return $this;  
    }  
    public function getTweets(){  
        $this->twitterArr = $this->getTimelineArray();  
        $tweets = array();  
        foreach($this->twitterArr->status as $status){  
            $tweets[$status->created_at->__toString()] = $status->text->__toString();  
        }  
        return $tweets;  
    }  
    public function getTimelineArray(){  
        return simplexml_load_string($this->xml);  
    }  
    public function formatTweet($tweet){  
        $tweet = preg_replace("/(http(.+?))( |$)/","$1$3", $tweet);  
        $tweet = preg_replace("/#(.+?)(\h|\W|$)/", "#$1$2", $tweet);  
        $tweet = preg_replace("/@(.+?)(\h|\W|$)/", "@$1$2", $tweet);  
        return $tweet;  
    }  


19b. Tweeter Feed Runner——用于在主题中创建文件,比如:example.php

复制代码 代码如下:


loadTimeline("phpsnips")->getTweets();  
foreach($feed as $time => $message){  
    echo "<div>".$twitter->formatTweet($message)."<br />At: ".$time."</div>";  

您可能感兴趣的文章:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/c4bfac918b395e4e7acbe8571dfee12a.html