Last active
December 29, 2015 00:19
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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