允许在HTMLPurifier中解析完整的html [英] Allowing full html to be parsed in HTMLPurifier

查看:55
本文介绍了允许在HTMLPurifier中解析完整的html的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我很长一段时间以来遇到的问题-我目前接受用户输入完整的html页面作为输入,并希望对其进行过滤/清除.HTMLpurifier的问题在于它会删除head,html和body标签-以及head中的样式.我已经在google上浏览了论坛,试图实现所写的内容,但是没有运气.有人可以帮忙吗?

This is a problem I've had for a long time - I currently accept a full html page from the user as input and want to filter / clean it out. the problem with HTMLpurifier is that it removes the head , html , and body tags - as well as the styles in the head. I've google , looked at the forums , tried implementing what was written , and to no luck. Can someone help ?

我想要的是:保留HTML,HEAD,STYLE,BODY TAGS

What I want : To keep the HTML , HEAD , STYLE , BODY TAGS

我做了什么:

$config->set('HTML.DefinitionID', 'test');
    $config->set('HTML.DefinitionRev', 1);
    $config->set('HTML.AllowedElements', array('html','head', 'body', 'style', 'div', 'p'));    

    if ($def = $config->maybeGetRawHTMLDefinition()) {
        $def->addElement('html', 'Block', 'Inline', 'Common', array());
        $def->addElement('head', 'Block', 'Inline', 'Common', array());
        $def->addElement('style', 'Block', 'Inline', 'Common', array());
        $def->addElement('body', 'Block', 'Inline', 'Common', array());

    }

推荐答案

最终结果-HTMLPurfier本身不支持完整的HTML解析-要么扩展它要么通过查找通过

End Result - HTMLPurfier does not natively allow full HTML Parsing - Either extend it or find a pass thru

这篇关于允许在HTMLPurifier中解析完整的html的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆