Created
March 25, 2012 14:00
-
-
Save coreyweb/2194781 to your computer and use it in GitHub Desktop.
Twitter: rewrite URLs and replies as links
This file contains 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 | |
// Convert URL's with protocol prefix | |
$text = ereg_replace("[a-zA-Z]+://([-]*[.]?[a-zA-Z0-9_/-?&%])*", "<a href=\"\\0\">\\0</a>", $text); | |
//Convert URL with just www. | |
$text = ereg_replace("(^| |\n)(www([-]*[.]?[a-zA-Z0-9_/-?&%])*)", "\\1<a href=\"http://\\2\">\\2</a>", $text); | |
//Convert @ replies | |
$text = ereg_replace("(^| |\n)(\@([-]*[.]?[a-zA-Z0-9_/-?&%])*)", "\\1<a href=\"http://www.twitter.com/\\2\">\\2</a>", $text); | |
$text = str_replace("/@", "/", $text); | |
return $text; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment