php 读取twitter feed的简单示例

前端之家收集整理的这篇文章主要介绍了php 读取twitter feed的简单示例前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
PHP读取twitter Feed感兴趣的小伙伴,下面一起跟随编程之家 jb51.cc的小编两巴掌来看看吧!

<?PHP 
/**
 * PHP读取twitter Feed
 *
 * @param 
 * @author 编程之家 jb51.cc jb51.cc
 **/
class Twitter{ 
	protected $twitURL = 'http://api.twitter.com/1/'; 
	protected $xml; 
	protected $tweets  = array(),$twitterArr = array(); 
	protected $pversion = "1.0.0"; 
	public function pversion(){ 
		return $this->pversion; 
	} 
	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(.+?))( |$)/","<a href=\"$0\">$1</a>$3",$tweet); 
		$tweet = preg_replace("/#(.+?)(\h|\W|$)/","<a href=\"https://twitter.com/i/#!/search/?q=%23$1&src=hash\">#$1</a>$2",$tweet); 
		$tweet = preg_replace("/@(.+?)(\h|\W|$)/","<a href=\"http://twitter.com/#!/$1\">@$1</a>$2",$tweet); 
		return $tweet; 
	} 
}


/***   来自编程之家 jb51.cc(jb51.cc)   ***/
原文链接:https://www.f2er.com/php/528756.html

猜你在找的PHP相关文章