PHP 与HTML Purifier 错误:未定义变量:dirty_html

发布于 2024-08-26 22:31:51 字数 1238 浏览 7 评论 0原文

我正在尝试安装 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

最初的梦 2024-09-02 22:31:51

目前还不清楚你想要净化什么。一些 $_POST 变量?您收到该错误是因为您尚未定义 $dirty_html。例如,如果您想净化 about_me 字段,请使用

$clean_html = $purifier->purify($_POST['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

$clean_html = $purifier->purify($_POST['about_me']);
嘿嘿嘿 2024-09-02 22:31:51

$dirty_html 应该是网页的 HTML

看起来您正在向 HTML 添加 DOCTYPE 和编码,所以我假设您会像这样使用它:

$dirty_html =<<<DIRTYHTML
<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>
DIRTYHTML;

$clean_html = $purifier->purify($dirty_html);
echo $clean_html;

$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:

$dirty_html =<<<DIRTYHTML
<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>
DIRTYHTML;

$clean_html = $purifier->purify($dirty_html);
echo $clean_html;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文