【发布时间】:2016-09-19 02:01:45
【问题描述】:
我有这个函数,它为字符串中包含的每个@username 着色
//color @username
function hashtag_links($string,$id_session) {
preg_match_all('/@(\w+)/',$string,$matches);
foreach ($matches[1] as $match) {
$string = str_replace("@$match", "<span class=color>@$match</span>", "$string");
}
return $string;
}
虽然用户名不同(@cat、@pencil、@scubadiving)一切都很好,但如果用户名以相同的字母开头(@cat、@catrpiller、@cattering),函数只会为重复的字母着色在这种情况下(@cat),该怎么办?
【问题讨论】:
标签: php function twitter preg-match-all hashtag