p3k/ html-sanitizer
一个具有良好默认设置的HTML净化器
0.1.2
2022-11-19 16:03 UTC
Requires
- ezyang/htmlpurifier: ^4.12
Requires (Dev)
- phpunit/phpunit: ^8.4
README
一个具有良好默认设置的HTML净化器,可用于在应用程序中显示不受信任的HTML。
仅允许基本格式化标签集,删除所有<script>
标签。删除允许标签的所有属性,除了在Microformats 2类中留下。
安装
composer require p3k/html-sanitizer
使用方法
$output = p3k\HTML::sanitize($input);
选项
您可以向sanitize函数传递的最小数量选项
$options = [
'baseURL' => 'https://example.com/'
];
$output = p3k\HTML::sanitize($input, $options);
baseURL
- (默认false
)allowImg
- (true
/false
, 默认true
) - 是否允许输出中的img
标签allowMf2
- (true
/false
, 默认true
) - 是否允许元素上的Microformats 2类allowTables
- (true
/false
, 默认false
) - 是否允许表格元素(table
、thead
、tbody
、tr
、td
)
允许的标签
以下HTML标签是输入中唯一允许的标签。其他所有内容都将被删除。
a
abbr
b
br
code
del
em
i
q
strike
strong
time
blockquote
pre
p
h1
h2
h3
h4
h5
h6
ul
li
ol
span
hr
img
- 仅当$options['allowImg']
为true
时table
、thead
、tbody
、tfoot
、tr
、th
、td
- 仅当$options['allowTables']
为true
时
以下属性以外的所有属性都将被删除。
<a>
-href
<img>
-src width height alt
<time>
-datetime
如果$options['allowMf2']
为true
,则将删除class属性,但保留Microformats 2类值。
例如
<h2 class="p-name name">Hello</h2>
将变成
<h2 class="p-name">Hello</h2>