How to remove HTML tags in PHP?

I am using the htmlspecialchars function in my line. But I don’t want to clean them,

<b>, <br>, <p> <ul>,<li> bla bla...

Example: Mystring = "<script>.....</script><br><b>test</b><p>aaaa</p>";

I want to; =

<script>.....</script>
+3
source share
4 answers

Check out the HTML cleaner , and especially the whitelist .

This is probably the safest approach if you allow HTML tags. You can see the comparison here .

+7
source

Do you want to delete all tags? Use strip_tags () .

+3
source

PHP: strip_tags($text, '<p><a><li><b>');

- , HTML .

In the above example, I clear $ text from all tags except <p><a><li><b>;

This PHP function will clear user input if you don't submit <script>or </div>to break your page.

+1
source

Source: https://habr.com/ru/post/1736879/


All Articles