How to remove html tags in php?

I posted some data using tinymce (in a symfony project). Going back, how can I remove html tags? strip_tags does not work.

+4
source share
6 answers

An easy way is to use strip_tags , but it is not very reliable. There is a very, very, VERY good project for this: HTML Cleaner .

He is smitten, tested and very good. strip_tags is a simple, fast and fast way, but it may skip some kind of incorrect HTML code that the browser will parse and execute.


Please do not use regex to parse html!

+13
source

Note that strip_tags returns the string new . It does not change the original string, i.e.

 $html = '<p>Test</p>'; strip_tags($html); // Throws away the result, since you don't assign the return // value of the function to a variable $stripped = strip_tags($html); echo $stripped; // echos 'Test' 
+3
source

Try the following:

 echo strip_tags($this->getContent(ESC_RAW)) 
+2
source

You can use strip_tags :

 strip_tags('your text or variable'); 

It should work in symfony. Make sure you do everything right.

+1
source

When using Symfony, be sure to use the getRaw () function, otherwise the text cannot be removed from the HTML code, for example:

$ myText = $ sf_data-> getRaw ('myVarContainingText');

Then use strip_tags () as such:

$ myText = strip_tags ($ sf_data-> getRaw ('myVarContainingText'));

+1
source

strip_tags (); you need to put everything that has ever been completed using html ............

+1
source

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


All Articles