PHP packaged Twitter Access class instance, _php tutorial

Source: Internet
Author: User

PHP-encapsulated Twitter Access class instance,


The examples in this article describe the Twitter access classes in PHP encapsulation. Share to everyone for your reference. Specific as follows:

Class Twitter {/** * Method to do Twitter API call for the users timeline in XML * * @access private * @param $twit  ter_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 ') = = =) {$xml = new simplexmlelement ($response);  return $xml;  } else {return false;  }}/** * Method to add hyperlink HTML tags to any URLs, Twitter IDs or hashtags in tweets * * @access private * @param  $text * @return $text */Private Function Process_links ($text) {$text = Utf8_decode ($text); $text = Preg_replace (' @ (https?:/ /([-\w\.] +) + (d+)? (/([\w/_\.] * (\?\s+)?)?) @ ', ' $', $text); $text = Preg_replace ("# (^|[  \ n]) @ ([^ \ "\t\n\r<]*) #ise", "' \\1@\\2 '", $text); $text = Preg_replace ("# (^|[  \ n]) \# ([^ \ "\t\n\r<]*) #ise", "' \\1#\\2 '", $text); return $text; }/** * Main method to retrieve the tweets and return HTML for display * * @access public * @param $twitter _id, $num _o F_tweets, $timezone * @return $result */Public Function get_tweets ($twitter _id, $num _of_tweets = 3, $timezone = "Americ  A/denver ") {$include _replies = false;  Date_default_timezone_set ($timezone);  The HTML markup $cont _o = "\ n";  $tweet _o = "\ n";  $tweet _c = "\ n";  $detail _o = "\ n";  $detail _c = "\ n";  $cont _c = "\ 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 being unavailable at the moment." $tweet _c.  $cont _c; } return $result; }}

I hope this article is helpful to everyone's PHP programming.

http://www.bkjia.com/PHPjc/1034539.html www.bkjia.com true http://www.bkjia.com/PHPjc/1034539.html techarticle PHP encapsulated Twitter Access class instance, this article describes the PHP package of the Twitter access class. Share to everyone for your reference. The following are the details: class Twitter {/** * Method to make twit ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.