Search code examples
twittertwitter-rest-api

get twitter api in html format


i used twitter user_timeline api to pull the tweets,there i found a property name of text,can i get the tweets in html format so that my hyperlinks may start working inside my loops to display.

i am using TwitterAPIExchange.php library for php

$url = 'https://api.twitter.com/1.1/statuses/user_timeline.json';
$getfield = '?username=arpia';
$requestMethod = 'GET';
$twitter = new TwitterAPIExchange($settings);
$tw=$twitter->setGetfield($getfield)
             ->buildOauth($url, $requestMethod)
             ->performRequest();      

how can i display linked #tags uploaded images and other html entities


Solution

  • you can use this function:

       function linkify_tweet($tweet) {
    
      //Convert urls to <a> links
      $tweet = preg_replace("/([\w]+\:\/\/[\w-?&;#~=\.\/\@]+[\w\/])/", "<a target=\"_blank\" href=\"$1\">$1</a>", $tweet);
    
      //Convert hashtags to twitter searches in <a> links
      $tweet = preg_replace("/#([A-Za-z0-9\/\.]*)/", "<a target=\"_new\" href=\"http://twitter.com/search?q=$1\">#$1</a>", $tweet);
    
      //Convert attags to twitter profiles in <a> links
      $tweet = preg_replace("/@([A-Za-z0-9\/\.]*)/", "<a href=\"http://www.twitter.com/$1\">@$1</a>", $tweet);
    
      return $tweet;
    
    }
    

    found here: http://www.jacobtomlinson.co.uk/2014/01/22/convert-tweet-hashtags-at-tags-and-urls-to-links-with-php-and-regular-expressions/