Created
July 28, 2010 13:25
-
-
Save pavelmaca/494497 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
<?php | |
//regex test: http://regexhero.net/tester/?id=c4b2c455-b1e3-40b8-969e-b5b8240b7324 | |
public static function twitterify($text) { | |
$search = array( | |
'|(http://[^ ]+)|', | |
'/(^|[^a-z0-9_])@(\w*[a-z]+[0-9a-ž_]*)/i', | |
'/(^|[^a-z0-9_])#(\w*[a-z]+[0-9a-ž_]*)/i', | |
); | |
$replace = array( | |
'<a href="$1" title="$1">$1</a>', | |
'$1<a href="http://twitter.com/$2" title="$2">@$2</a>', | |
'$1<a href="http://twitter.com/search?q=%23$2" title="$2">#$2</a>', | |
); | |
return preg_replace($search, $replace, $text); | |
} | |
?> |
fprochazka
commented
Jul 28, 2010
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment