成人精品一区二区三区中文字幕-成人精品一区二区三区-成人精品一级毛片-成人精品亚洲-日本在线视频一区二区-日本在线视频免费

導航首頁 ? 技術教程 ? PHP封裝的Twitter訪問類實例
全站頭部文字 我要出現在這里
PHP封裝的Twitter訪問類實例 747 2023-12-08   

本文實例講述了PHP封裝的Twitter訪問類。分享給大家供大家參考。具體如下:

class Twitter {
 /**
  * Method to make twitter api call for the users timeline in XML
  *
  * @access private
  * @param $twitter_id, $num_of_tweets
  * @return $xml
  */
 private function api_call($twitter_id, $num_of_tweets) {
  $c = curl_init();
  curl_setopt($c, CURLOPT_URL, "http://twitter.com/statuses/user_timeline/$twitter_id.xml?count=$num_of_tweets");
  curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($c, CURLOPT_CONNECTTIMEOUT, 3);
  curl_setopt($c, CURLOPT_TIMEOUT, 5);
  $response  = curl_exec($c);
  $response_info = curl_getinfo($c);
  curl_close($c);
  if (intval($response_info['http_code']) == 200) {
   $xml = new SimpleXMLElement($response);
   return $xml;
  } else {
   return false;
  }
 }
 /**
  * Method to add hyperlink html tags to any urls, twitter ids or hashtags in tweet
  *
  * @access private
  * @param $text
  * @return $text
  */
 private function process_links($text) {
  $text = utf8_decode($text);
  $text = preg_replace('@(https?://([-w.]+)+(d+)?(/([w/_.]*(?S+)?)?)?)@', '<a , $text);
  $text = preg_replace("#(^|[n ])@([^ "tnr<]*)#ise", "'\1<a  >@\2</a>'", $text);
  $text = preg_replace("#(^|[n ])#([^ "tnr<]*)#ise", "'\1<a  >#\2</a>'", $text);
  return $text;
 }
 /**
  * Main method to retrieve the tweets and return html for display
  *
  * @access public
  * @param $twitter_id, $num_of_tweets, $timezone
  * @return $result
  */
 public function get_tweets($twitter_id, $num_of_tweets = 3, $timezone = "America/Denver") {
  $include_replies = false;
  date_default_timezone_set($timezone);
  // the html markup
  $cont_o  = "<div id="tweets">n";
  $tweet_o = "<div class="status">n";
  $tweet_c = "</div>nn";
  $detail_o = "<div class="details">n";
  $detail_c = "</div>nn";
  $cont_c  = "</div>n";
  if ($twitter_xml = $this->api_call($twitter_id, $num_of_tweets)) {
   $result  = $cont_o;
   foreach ($twitter_xml->status as $key => $status) {
    if ($include_replies == true | substr_count($status->text, "@") == 0 | strpos($status->text, "@") != 0) {
     $tweet = $this->process_links($status->text);
     $result .= $tweet_o . $tweet . $tweet_c . $detail_o . date('D jS M y H:i', strtotime($status->created_at)) . $detail_c;
    }
   }
   $result  .= $cont_c;
  } else {
   $result  .= $cont_o . $tweet_o . "Twitter seems to be unavailable at the moment." . $tweet_c . $cont_c;
  }
  return $result;
 }
}

希望本文所述對大家的php程序設計有所幫助。


主站蜘蛛池模板: 宇宙刑事夏伊达| 包青天之真假包公| 无锡电视台| 我在等你回家剧情介绍| 山上的小屋 残雪| 未删减视频| 伊人春色在线观看视频| 欲望之城 电影| 老友记 第一季 1994 詹妮弗·安妮斯顿| 基础综合英语邱东林电子版答案| 谍中谍7| 营业执照注销打什么电话咨询| 处女巫| 买买提个人资料简历| 相声《别人家的孩子》| 让我听懂你的语言歌词| 博朗耳温枪| 谭老板 电影| 意大利 艾伦 温暖的夜晚| 十八岁在线观看| 米奇888| 张静芝| 夏希粟| 九号所有车型图片| 甜蜜监狱| 香港九龙图库精选资料| 在线观看www视频| 金首露| cgtn英语频道在线直播观看| 让我们的家更美好教学设计| 英语书七年级下册单词表| 金酸梅奖| 经典常谈周易第二读书笔记| 迟志强简历| 美妙旋律| 历史试卷反思| 人设oc素材| 10000个卫视频道| 少年班演员表| 咖啡王子一号店| 囚禁空姐|

!!!站長長期在線接!!!

網站、小程序:定制開發/二次開發/仿制開發等

各種疑難雜癥解決/定制接口/定制采集等

站長微信:lxwl520520

站長QQ:1737366103