PHP:搜索所有Twitter用户名的字符串并提取它们

I have a string, and I need to extract all the twitter usernames from the string. Example:

Hello @twitter and @facebook

I need both those to go into an array with a possible count value too.

So it would look like this:

$username[0] = "twitter";
$username[1] = "facebook";

And I need this for any amount of usernames that can fit into a tweet.

To take this a step further, I needs this so I can turn a simple tweet into one with links.

So

Hello @twitter and @facebook

becomes

Hello <a href="http://twitter.com/twitter">@twitter</a> and <a href="http://twitter.com/facebook">@facebook</a>

Thus rewriting it.

You can do it easily with regex. This is what you should do for replacing twitter usernames

$text = preg_replace('/@(\w+)\b/i', '<a href="http://twitter.com/$1">@$1</a>', $text);

For extracting usernames, you should use preg_match_all instead.