Whitelist and blacklist HTML tags.
\Nullai\Hygiene\SanitizeHtml::filterTags()
method is a powerful tool for sanitizing HTML content by allowing or blacklisting specific HTML tags and their attributes. This feature is particularly useful for ensuring secure and clean user-generated content.
:
. For example, a:href|class
allows the href
and class
attributes for <a>
tags.p
targets the <p>
tag.true
: Whitelist mode — allows only the specified tags and attributes.false
: Blacklist mode — removes the specified tags and attributes.<p>
and <a>
tags, preserving the href
and class
attributes for <a>
. All other tags and attributes will be removed.
<iframe>
and <script>
tags from the input HTML while leaving other tags intact.
<p>
, <strong>
) for user-submitted content.<script>
or <iframe>
.\Nullai\Hygiene\SanitizeHtml::filterTags()
, you can easily implement secure and customizable HTML sanitization in your applications.