1
我有一个网站,人们将提交文本。我想为添加的链接添加一些属性。任何人都知道正则表达式(或另一种好方法)将rel =“nofollow”添加到提交文本正文中的任何链接?将属性添加到提交的内容链接
我有一个网站,人们将提交文本。我想为添加的链接添加一些属性。任何人都知道正则表达式(或另一种好方法)将rel =“nofollow”添加到提交文本正文中的任何链接?将属性添加到提交的内容链接
使用DOM解析(PHP Simple HTML DOM Parser为例):
// Create DOM from string
$html = str_get_html($links);
$linksCount = count($html->find('a'));
for($i=0;$i<$linksCount;$i++) {
$html->find('a', $i)->rel = 'nofollow';
}
echo $html;
感谢。这看起来像一个漂亮的下降解决方案。 – 2009-09-23 18:18:40