PHP 与HTML Purifier 错误:未定义变量:dirty_html
我正在尝试安装 HTML Purifier http://htmlpurifier.org/ 但收到以下错误未定义变量: dirty_html。我想知道如何解决这个问题?
这是 PHP 代码。
require_once '../../htmlpurifier/library/HTMLPurifier.auto.php';
$config = HTMLPurifier_Config::createDefault();
$config->set('Core.Encoding', 'UTF-8'); // replace with your encoding
$config->set('HTML.Doctype', 'XHTML 1.0 Strict'); // replace with your doctype
$purifier = new HTMLPurifier($config);
$clean_html = $purifier->purify($dirty_html);
这是我的 html 表单。
<form method="post" action="index.php">
<fieldset>
<ul>
<li><label for="about-me">About Me: </label>
<textarea rows="8" cols="60" name="about-me" id="about-me"></textarea></li>
<li><label for="my-interests">My Interests: </label>
<textarea rows="8" cols="60" name="interests" id="interests"></textarea></li>
<li><input type="submit" name="submit" value="Save Changes" class="save-button" />
</ul>
</fieldset>
</form>
I'm trying to install HTML Purifier http://htmlpurifier.org/ but I get the following error Undefined variable: dirty_html. I was wondering how can I fix this problem?
Here is the PHP code.
require_once '../../htmlpurifier/library/HTMLPurifier.auto.php';
$config = HTMLPurifier_Config::createDefault();
$config->set('Core.Encoding', 'UTF-8'); // replace with your encoding
$config->set('HTML.Doctype', 'XHTML 1.0 Strict'); // replace with your doctype
$purifier = new HTMLPurifier($config);
$clean_html = $purifier->purify($dirty_html);
Here is my html form.
<form method="post" action="index.php">
<fieldset>
<ul>
<li><label for="about-me">About Me: </label>
<textarea rows="8" cols="60" name="about-me" id="about-me"></textarea></li>
<li><label for="my-interests">My Interests: </label>
<textarea rows="8" cols="60" name="interests" id="interests"></textarea></li>
<li><input type="submit" name="submit" value="Save Changes" class="save-button" />
</ul>
</fieldset>
</form>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
目前还不清楚你想要净化什么。一些 $_POST 变量?您收到该错误是因为您尚未定义
$dirty_html
。例如,如果您想净化 about_me 字段,请使用It's not clear what you want to purify. Some $_POST vars? You get that error because you have not defined
$dirty_html
. For example, if you want to purify the about_me field, use$dirty_html 应该是网页的 HTML
看起来您正在向 HTML 添加 DOCTYPE 和编码,所以我假设您会像这样使用它:
$dirty_html should be the HTML of the webpage
It looks like you're adding a DOCTYPE and Encoding to your HTML so I assumed that you would use it like this: