从标签 a 中删除属性 rel follow 并替换值 nofollow

Remove attribute rel follow from Tag a and replace value nofollow

我想删除标签 a 后面的属性 rel 并使用 PHP 或 Yii2、Regex 或 HtmlPurifier 将值替换为 nofollow

我用的是Yii2

内容:

<a href="http://www.hgjhg.com" rel="follow">
<a href="http://www.gggg.com">
<a href="http://www.kjhjg.com/511" rel="nofollow">

我愿意:

<a href="http://www.hgjhg.com" rel="nofollow">
<a href="http://www.gggg.com" rel="nofollow">
<a href="http://www.kjhjg.com/511" rel="nofollow">

添加 nofollow 标记

public static function addNoFollow($html)
{
     $result = HtmlPurifier::process($html, function ($config) {
     $config->set('HTML.Nofollow', true);
     });

     return $result;
}