tags:

views:

867

answers:

4

i posted some data using tinymce (in a symfony project).while retrieving back how can i remove html tags? strip_tags not working..

+1  A: 

You could use strip_tags:

strip_tags('your text or variable');

It should work in symfony. Make sure that you have done everything correctly.

Sarfraz
i gave for ex: echo strip_tags($var); then it is printing all the html tags also
A: 

you can try this:

$myString = ereg_replace("<[^>]*>", "", $myString)
Getz
i am getting this error" Deprecated: Function ereg_replace() is deprecated in showSucess line 4"
It's not en error in php 5.3 :http://be2.php.net/manual/en/function.ereg-replace.php
Getz
It's not an error in PHP 5.3? Your link contains a massive warning "This function has been DEPRECATED as of PHP 5.3.0". There is no reason to suggest the deprecated ereg_* functions when preg_* exists. That's before its pointed out that regex is not the best way to strip HTML. Try giving it a string like "so lets assume that x < y and y > z"
Simon
+7  A: 

The easies way is to use strip_tags but it's not very reliable. There is a very, very, VERY good project design specifically for this: HTML Purifier.

It battle-hardened, tested and very good. strip_tags is the easy, fast and go way, but it can miss out some malformated html that a browser will actually parse and execute.


Please, don't use regular expression to parse html!

Emil Ivanov
Thanks for such a wonderful information share 'Emil'. I will use it in my next project.
Gaurav Sharma
+3  A: 

Note that strip_tags returns a new string. It does not modify 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'
PatrikAkerstrand