我試圖讓HTML淨化器過濾器中的元素的rel屬性。我按照本指南http://htmlpurifier.org/docs/enduser-customize.html這裏是我的代碼:將屬性添加到HTML淨化器過濾器?
$config = HTMLPurifier_Config::createDefault();
$config->set('HTML.Doctype', 'XHTML 1.0 Strict');
$config->set('HTML.DefinitionID', 'enduser-customize.html tutorial');
$config->set('HTML.DefinitionRev', 1);
$config->set('Cache.DefinitionImpl', null); // remove this later!
$def = $config->getHTMLDefinition(true);
$def->addAttribute('a', 'href*', 'URI');
$def->addAttribute('a', 'rel', 'CDATA');
$purifier = new HTMLPurifier($config);
然而,HTML淨化器還過濾掉所有屬性相對......我有點困惑的問題可能是什麼。
當我使用:
$config->set('Attr', 'AllowedRel', array('something'));
我得到這個錯誤:
Notice: Using deprecated API: use
$config->set('Attr.AllowedRel', ...)
instead on line 191 in fileC:\wamp\www\neonet\application\modules\admin\controllers\IndexController.php
inC:\wamp\www\neonet\library\My\htmlpurifier-4.0.0-standalone\HTMLPurifier.standalone.php
on line 1819
編輯:
新代碼:
$config = HTMLPurifier_Config::createDefault();
$config->set('HTML.Doctype', 'XHTML 1.0 Strict');
$config->set('Attr.AllowedRel', array('something'));
$purifier = new HTMLPurifier($config);
當我使用:
<href="/" rel="something">anchor</a>
Rel屬性仍然被過濾。
是的,但是當我嘗試使用它時,出現錯誤,請參閱上文,我編輯了我的帖子。 – 2009-11-10 18:00:39
確定忽略最後一條評論,我使用的是棄用的API ...但它仍然無效。 – 2009-11-10 18:04:18
謝謝,我會改變文檔類型。 – 2009-11-11 12:28:27