$users['pony'] = '马化腾';
$users['ponyma'] = '坡泥马';
$users['ponyli'] = '坡泥李';
$text = "@pony:特别声明,@ponyli@ponyma@ponywong@ponylao什么的都不是我";
preg_match_all(
'/@w+/', $text, $matches);
if(is_array($matches[0]) && !empty($matches[0])){
$replaces = array_combine($matches[0], $matches[0]);
}
foreach($users as $userid=>$username){
$replaces['@'.$userid] = "<a href='http://t.qq.com/{$userid}'>{$username}</a>";
}
$html = strtr($text, $replaces);
echo $html;
<a href=’http://t.qq.com/pony’>马化腾</a>:特别声明,<a href=’http://t.qq.com/ponyli’>坡泥李</a><a href=’http://t.qq.com/ponyma’>坡泥马</a>@ponywong@ponylao什么的都不是我