찾다
php教程PHP源码封装 Twitter 访问的 PHP 类

跳至

<?php

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[&#39;http_code&#39;]) == 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(&#39;@(https?://([-\w\.]+)+(d+)?(/([\w/_\.]*(\?\S+)?)?)?)@&#39;, &#39;$1&#39;, $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(&#39;D jS M y H:i&#39;, 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;
    }

}

                   

성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.

핫 AI 도구

Undresser.AI Undress

Undresser.AI Undress

사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover

AI Clothes Remover

사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool

Undress AI Tool

무료로 이미지를 벗다

Clothoff.io

Clothoff.io

AI 옷 제거제

AI Hentai Generator

AI Hentai Generator

AI Hentai를 무료로 생성하십시오.

뜨거운 도구

SublimeText3 중국어 버전

SublimeText3 중국어 버전

중국어 버전, 사용하기 매우 쉽습니다.

SublimeText3 Mac 버전

SublimeText3 Mac 버전

신 수준의 코드 편집 소프트웨어(SublimeText3)

맨티스BT

맨티스BT

Mantis는 제품 결함 추적을 돕기 위해 설계된 배포하기 쉬운 웹 기반 결함 추적 도구입니다. PHP, MySQL 및 웹 서버가 필요합니다. 데모 및 호스팅 서비스를 확인해 보세요.

드림위버 CS6

드림위버 CS6

시각적 웹 개발 도구

DVWA

DVWA

DVWA(Damn Vulnerable Web App)는 매우 취약한 PHP/MySQL 웹 애플리케이션입니다. 주요 목표는 보안 전문가가 법적 환경에서 자신의 기술과 도구를 테스트하고, 웹 개발자가 웹 응용 프로그램 보안 프로세스를 더 잘 이해할 수 있도록 돕고, 교사/학생이 교실 환경 웹 응용 프로그램에서 가르치고 배울 수 있도록 돕는 것입니다. 보안. DVWA의 목표는 다양한 난이도의 간단하고 간단한 인터페이스를 통해 가장 일반적인 웹 취약점 중 일부를 연습하는 것입니다. 이 소프트웨어는