tags:

views:

66

answers:

2

Hi Im looping over json response from Twitter api. Each api response give me a tweet, something like this:

Hi my name is @john, and I love #soccer, visit me

Im trying to replace @john, and insert <a href=http://twitter.com/john&gt;@john&lt;/a&gt;. BUT, the comma (,) after @john, is the problem.

How to replace dots, commas, etc before and after the tag?

+1  A: 
$str = preg_replace("/@([a-z_0-9]+)/i", "<a href=\"http://twitter.com/$1\"&gt;$0&lt;/a&gt;", $str);
Tim Cooper
Sorry, SO didn't notify me someone has already posted an answer.
racetrack
+1  A: 
preg_replace("/@(\w+)/", "<a href=http://twitter.com/$1&gt;@$1&lt;/a&gt;", $string)"
racetrack