Created
January 6, 2010 22:30
-
-
Save cange/270750 to your computer and use it in GitHub Desktop.
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
/** | |
* Twitter message String | |
* Searches in a string for links, replies, and hash and generates a <a>-Tag for the results. | |
* @param {String} message | |
* @return {String} | |
*/ | |
function generateLinks ($message) { | |
$pattern[0] = '/(http:\/\/[0-9a-z-_.\/]+)/i'; # find is urls | |
$pattern[1] = '/@([0-9a-z-_]+)/'; # find is replies | |
$pattern[2] = '/#([0-9a-z-_]+)/'; # find is hashes | |
$replace[0] = '<a href="$1" title="external">$1</a>'; | |
$replace[1] = '<a href="http://www.twitter.com/$1">@$1</a>'; | |
$replace[2] = '<a href="http://search.twitter.com/search?q=$1">#$1</a>'; | |
return preg_replace($pattern, $replace, $message); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment