How PHP encapsulates Twitter access classes
This article mainly introduces how PHP encapsulates the Twitter access class, which has a certain reference value. Interested friends can refer to it. I hope you can learn a lot after reading this article.
The details are as follows:
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 +)? (/ ([\ wAccord _\.] * (\?\ S+)) @','$1mm, $text); $text = preg_replace ("# (^ | [\ n]) @ ([^\"\ t\ n\ rapi_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 strtotime, 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;}} Thank you for reading this article carefully. I hope the article "how to encapsulate Twitter access classes in PHP" shared by the editor will be helpful to you. At the same time, I hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!