欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

PHP封裝的Twitter訪(fǎng)問(wèn)類(lèi)實(shí)例

 更新時(shí)間:2015年07月18日 10:50:48   作者:鑒客  
這篇文章主要介紹了PHP封裝的Twitter訪(fǎng)問(wèn)類(lèi),通過(guò)curl調(diào)用實(shí)現(xiàn)針對(duì)Twitter的常用訪(fǎng)問(wèn)功能,具有一定參考借鑒價(jià)值,需要的朋友可以參考下

本文實(shí)例講述了PHP封裝的Twitter訪(fǎng)問(wèn)類(lèi)。分享給大家供大家參考。具體如下:

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 href="$1">$1</a>', $text);
  $text = preg_replace("#(^|[\n ])@([^ \"\t\n\r<]*)#ise", "'\\1<a href=\"http://www.twitter.com/\\2\" >@\\2</a>'", $text);
  $text = preg_replace("#(^|[\n ])\#([^ \"\t\n\r<]*)#ise", "'\\1<a href=\"http://hashtags.org/search?query=\\2\" >#\\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>\n\n";
  $detail_o = "<div class=\"details\">\n";
  $detail_c = "</div>\n\n";
  $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;
 }
}

希望本文所述對(duì)大家的php程序設(shè)計(jì)有所幫助。

相關(guān)文章

  • PHP實(shí)現(xiàn)的簡(jiǎn)單組詞算法示例

    PHP實(shí)現(xiàn)的簡(jiǎn)單組詞算法示例

    這篇文章主要介紹了PHP實(shí)現(xiàn)的簡(jiǎn)單組詞算法,涉及php針對(duì)字符串的遍歷、遞歸、組合、運(yùn)算等相關(guān)操作技巧,需要的朋友可以參考下
    2018-04-04
  • PHP實(shí)時(shí)統(tǒng)計(jì)中文字?jǐn)?shù)和區(qū)別

    PHP實(shí)時(shí)統(tǒng)計(jì)中文字?jǐn)?shù)和區(qū)別

    今天小編就為大家分享一篇關(guān)于PHP統(tǒng)計(jì)實(shí)時(shí)統(tǒng)計(jì)漢字個(gè)數(shù)和區(qū)別,小編覺(jué)得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來(lái)看看吧
    2019-02-02
  • 在VS2008中編譯MYSQL5.1.48的方法

    在VS2008中編譯MYSQL5.1.48的方法

    WINDOWS下編譯MYSQL5.1.48,在VS2008中運(yùn)行
    2010-07-07
  • discuz的php防止sql注入函數(shù)

    discuz的php防止sql注入函數(shù)

    最早開(kāi)始學(xué)習(xí)php的時(shí)候根本沒(méi)考慮過(guò)安全方面的問(wèn)題,那時(shí)候就是想能做出功能就是萬(wàn)歲了。隨著做項(xiàng)目的時(shí)間慢慢加長(zhǎng),越來(lái)越感覺(jué)到網(wǎng)站安全方面的問(wèn)題十分重要。
    2011-01-01
  • php中chdir()函數(shù)用法實(shí)例

    php中chdir()函數(shù)用法實(shí)例

    這篇文章主要介紹了php中chdir()函數(shù)用法,以實(shí)例形式簡(jiǎn)單講述了chdir實(shí)現(xiàn)切換目錄的方法,需要的朋友可以參考下
    2014-11-11
  • 由php中字符offset特征造成的繞過(guò)漏洞詳解

    由php中字符offset特征造成的繞過(guò)漏洞詳解

    這篇文章主要給大家介紹了關(guān)于由php中字符offset特征造成的繞過(guò)漏洞的相關(guān)資料,文中不僅詳細(xì)介紹了該漏洞的形成,更重要的是介紹了修復(fù)方式,對(duì)大家具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起看看吧。
    2017-07-07
  • php自定義函數(shù)實(shí)現(xiàn)漢字轉(zhuǎn)換utf8編碼的方法

    php自定義函數(shù)實(shí)現(xiàn)漢字轉(zhuǎn)換utf8編碼的方法

    這篇文章主要介紹了php自定義函數(shù)實(shí)現(xiàn)漢字轉(zhuǎn)換utf8編碼的方法,涉及php針對(duì)字符串的遍歷、截取及編碼轉(zhuǎn)換相關(guān)操作技巧,需要的朋友可以參考下
    2016-09-09
  • PHP以指定字段為索引返回?cái)?shù)據(jù)庫(kù)所取的數(shù)據(jù)數(shù)組

    PHP以指定字段為索引返回?cái)?shù)據(jù)庫(kù)所取的數(shù)據(jù)數(shù)組

    本文與大家分享幾個(gè)使用得PHP編程技巧,有些技巧是在看別人代碼的時(shí)候?qū)W來(lái)的,有些是自己總結(jié)的,下面為大家介紹下以特定字段為索引,返回?cái)?shù)據(jù)庫(kù)取的數(shù)據(jù)數(shù)組,感興趣的朋友可以了解下哈
    2013-06-06
  • PHP中的錯(cuò)誤處理、異常處理機(jī)制分析

    PHP中的錯(cuò)誤處理、異常處理機(jī)制分析

    在編寫(xiě)php程序時(shí),錯(cuò)誤處理是一個(gè)重要的部分。如果程序中缺少錯(cuò)誤檢測(cè)代碼,那么看上去很不專(zhuān)業(yè),也為安全風(fēng)險(xiǎn)敞開(kāi)了大門(mén)
    2012-05-05
  • php將print_r處理后的數(shù)據(jù)還原為原始數(shù)組的解決方法

    php將print_r處理后的數(shù)據(jù)還原為原始數(shù)組的解決方法

    下面小編就為大家?guī)?lái)一篇php中將print_r處理后的數(shù)據(jù)還原為原始數(shù)組的方法。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考
    2016-11-11

最新評(píng)論