好的,我已经制作了这个函数,可以将大多数URL(如pies.com或www.cakes.com)转换为实际的链接标签。
function render_hyperlinks($str){
$regex = '/(http:\/\/)?(www\.)?([a-zA-Z0-9\-_\.]+\.(com|co\.uk|org(\.uk)?|tv|biz|me)(\/[a-zA-Z0-9\-\._\?&=#\+;]+)*)/ie';
$str = preg_replace($regex,"'<a href=\"http://www.'.'$3'.'\" target=\"_blank\">'.strtolower('$3').'</a>'", $str);
return $str;
}
我希望更新这个功能,将
no-follow
标签添加到指向我的竞争对手的链接中,所以我会选择某些关键词(竞争对手名称)来进行nofollow。例如,如果我的网站是关于烘焙的,我可能想要:
no-follow any sites with the phrases 'bakingbrothers', 'mrkipling', 'lyonscakes'
能否将if(contains x){ add y}
实现到我的正则表达式中?
这就是所谓的“回溯”吗?