Answer the question
In order to leave comments, you need to log in
How to filter HTML from XSS and stuff?
I have a wiziwig editor that generates HTML code, example:
<p class="line" id="line-1"><span style="color: rgb(230, 0, 0);"><span style="background-color: rgb(255, 153, 0);">affasf</span></span><span style="background-color: rgb(255, 255, 255);"><span style="color: rgb(230, 0, 0);"><span style="background-color: rgb(255, 153, 0);">dadssadasda</span></span></span></p><p class="line" id="line-35">эллэл</p><p class="line" id="line-43">шхохохх</p><p class="line" id="line-56"><span style="color: rgb(230, 0, 0);"><span style="background-color: rgb(255, 153, 0);"><b>dddddad</b></span></span></p>
[b] -> <b>
Answer the question
In order to leave comments, you need to log in
First, there is a solution like HTMLPurifier which removes all unresolved tags.
Secondly, simple autocorrect will not help, it is desirable to use regular expressions, in which if the tag is unpaired, it will not be parsed.
Thirdly, there are editors that generate BB markup. I really like WysiBB due to its light weight, great expandability and minimalist design.
If you are interested in this editor - I can throw off a set of rules for autocorrect.
Remember once and for all - HTML is filtered once, before being output to the browser.
If you are using PHP, there is a wonderful htmlspecialchars function. There are similar solutions for other languages.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question