I\'m making a news and comment system at the moment, but I\'m stuck at one part for a while now. I want users to be able to refer to other players on the twitter style like
Looks like a job for preg_replace_callback():
$string = preg_replace_callback('/@([a-z0-9_]+)/', function ($matches) {
if ($user = get_user_by_username(substr($matches[0], 1)))
return ''.$user['name'].'';
else
return $matches[0];
}, $string);