posted on 2009-05-12 - amd.im/ZoL2
Are you trying to add automatic hashtag and username hot linking in your PHP twitter app?
I just tried to do this with my amdavidson.me lifestreaming site. It's just two nested regular expressions. If there's some problem with nested preg_replace functions, or if any regular expression geniuses have better ideas, feel free to comment.
But if not, here's a little code for you, should make things super easy. It assumes your
tweet variable is $tweet, replace with whatever you'd need.
echo preg_replace('/\#([a-zA-Z0-9_]{1,15})?/',
"<a href=\"http://hashtags.org/tag/$1\">#$1</a>",
preg_replace('/\@([a-zA-Z0-9_]{1,15})?/',
"<a href=\"http://twitter.com/$1\">@$1</a>",
$tweet));
amdavidson.com is a simple blog run by Andrew Davidson, a manufacturing engineer with a blogging habit. He sometimes posts 140 character tidbits, shares photos, and saves links. You can also see posts dating back to 2005.