gpt4 book ai didi

php - 如何使用 PHP 允许 HTML 进入白名单

转载 作者:行者123 更新时间:2023-12-03 02:28:15 25 4
gpt4 key购买 nike

我知道多年来关于使用 PHP 过滤数据的最佳方法有很多讨论,但我想在当前的项目中采用白名单方法。

我只希望用户能够使用以下 HTML

<b>bold</b>
<i>italics</i>
<u>underline</u>
<s>strikethrough</s>
<big>Big size</big >
<small>Small size</small>

Hyperlink <a href="http://www.site.com">website</a>

A Bulleted List:
<ul>
<li>One Item</li>
<li>Another Item</li>
</ul>

An Ordered List:
<ol>
<li> First Item</li>
<li> Second Item</li>
</ol>

<blockquote>Because it is indented</blockquote>

<h1>Heading 1</h1>
<h2>Heading 2</h2>
<h3>Heading 3</h3>

任何人都可以告诉我在 PHP 中执行此操作以提高性能的最佳方法吗?我过去只允许所有 html 减去某些代码

最佳答案

我相信 HTML Purifier Library 会很好地工作:

<强> http://htmlpurifier.org/

HTML Purifier is a standards-compliant HTML filter library written in PHP. HTML Purifier will not only remove all malicious code (better known as XSS) with a thoroughly audited, secure yet permissive whitelist, it will also make sure your documents are standards compliant, something only achievable with a comprehensive knowledge of W3C's specifications. Tired of using BBCode due to the current landscape of deficient or insecure HTML filters? Have a WYSIWYG editor but never been able to use it? Looking for high-quality, standards-compliant, open-source components for that application you're building? HTML Purifier is for you!

关于php - 如何使用 PHP 允许 HTML 进入白名单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1975613/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com