Skip to content

Instantly share code, notes, and snippets.

@matrixfox
Last active December 29, 2015 00:19
Show Gist options
  • Save matrixfox/7584593 to your computer and use it in GitHub Desktop.
Save matrixfox/7584593 to your computer and use it in GitHub Desktop.
This makes use of Twitters API 1.1 Entities https://dev.twitter.com/docs/entities
<?php
$code = $tweets->text;
//Convert urls to <a> links
$code = preg_replace("/([\w]+\:\/\/[\w-?&;#~=\.\/\@]+[\w\/])/", "<a target=\"_blank\" href=\"$1\">$1</a>", $code);
//Convert hashtags to twitter searches in <a> links
$code = preg_replace("/#([A-Za-z0-9\/\.]*)/", "<a target=\"_new\" href=\"http://twitter.com/search?q=$1\">#$1</a>", $code);
//Convert attags to twitter profiles in <a> links
$code = preg_replace("/@([A-Za-z0-9\/\._]*)/", "<a href=\"http://www.twitter.com/$1\">@$1</a>", $code);
echo $code;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment