Php 向HTML净化器过滤器添加属性?
我试图在HTML净化器过滤器中的元素中允许rel属性。我遵循本指南,以下是我的代码:Php 向HTML净化器过滤器添加属性?,php,zend-framework,htmlpurifier,Php,Zend Framework,Htmlpurifier,我试图在HTML净化器过滤器中的元素中允许rel属性。我遵循本指南,以下是我的代码: $config = HTMLPurifier_Config::createDefault(); $config->set('HTML.Doctype', 'XHTML 1.0 Strict'); $config->set('HTML.DefinitionID', 'enduser-customize.html tutorial'); $config->set('HTML.DefinitionR
$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净化器仍在过滤掉所有rel属性。。。我有点困惑到底是什么问题
当我使用:
$config->set('Attr', 'AllowedRel', array('something'));
<href="/" rel="something">anchor</a>
我得到这个错误:
注意:使用不推荐使用的API:use$config->set('Attr.allowerel',…)
而不是在文件C:\wamp\www\neonet\application\modules\admin\controllers\IndexController.php的第191行中使用C:\wamp\www\neonet\library\My\htmlpurifier-4.0.0-standalone\htmlpurifier.standalone.php
1819行
编辑:
新代码:
$config = HTMLPurifier_Config::createDefault();
$config->set('HTML.Doctype', 'XHTML 1.0 Strict');
$config->set('Attr.AllowedRel', array('something'));
$purifier = new HTMLPurifier($config);
当我使用:
$config->set('Attr', 'AllowedRel', array('something'));
<href="/" rel="something">anchor</a>
锚定
Rel属性仍然会被过滤。给您。至于你的代码,它适用于我;也许你已经开启了魔法引号,或者没有正确刷新缓存?(在这种情况下,请尝试碰撞定义Rev。)
尝试使用rel时的另一个经典错误是,它不能与XHTML Strict一起工作;该doctype没有定义rel,因此Attr.AllowedRel不起任何作用(这应该在文档中提及,但不是)。因此,如果您想保留W3C复选标记或使用原始代码,您必须选择不同的doctype。是的,但当我尝试使用它时,会出现错误,请参见上文,我已编辑了我的帖子。确定忽略最后的注释,我正在使用不推荐的API。。。但是还是不行。谢谢,我会更改doctype。