0

我使用 twitter user_timeline api 来提取推文,在那里我找到了一个属性名称 text,我可以获取 html 格式的推文,以便我的超链接可以开始在我的循环中显示。

我正在使用TwitterAPIExchange.phpphp 库

$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();      

我如何显示链接#tags 上传的图像和其他html entities

4

1 回答 1

2

你可以使用这个功能:

   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;

}

在这里找到:http ://www.jacobtomlinson.co.uk/2014/01/22/convert-tweet-hashtags-at-tags-and-urls-to-links-with-php-and-regular-expressions/

于 2015-09-24T15:35:54.247 回答