if (preg_match('~@([\w]+)~iu', $url, $match)) {
$query = mysql_query("
SELECT * FROM `users`
WHERE `name` = '". mysql_real_escape_string($match[1]) ."'
");
$ud_st = mysql_fetch_assoc($query);
if (!empty($ud_st['id'])) {
$repl = '<a href="http://'. $_SERVER['HTTP_HOST'] .
'/users/profile.php?user='. $ud_st['id'] .'">'.
$match[0] .'</a>';
echo str_replace($match[0], $repl, $url);
} else {
echo str_replace($match[0], $match[1], $url);
}
} else {
echo $url;
}