2009-09-23 35 views
1

我有一個網站,人們將提交文本。我想爲添加的鏈接添加一些屬性。任何人都知道正則表達式(或另一種好方法)將rel =「nofollow」添加到提交文本正文中的任何鏈接?將屬性添加到提交的內容鏈接

回答

1

使用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; 
+0

感謝。這看起來像一個漂亮的下降解決方案。 – 2009-09-23 18:18:40