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
2010-03-12 10:38:15
i gave for ex: echo strip_tags($var); then it is printing all the html tags also
2010-03-12 10:42:22
i am getting this error" Deprecated: Function ereg_replace() is deprecated in showSucess line 4"
2010-03-12 10:46:44
It's not en error in php 5.3 :http://be2.php.net/manual/en/function.ereg-replace.php
Getz
2010-03-12 10:55:56
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
2010-03-12 11:04:23
+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
2010-03-12 10:43:40
Thanks for such a wonderful information share 'Emil'. I will use it in my next project.
Gaurav Sharma
2010-03-12 11:50:46
+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
2010-03-12 10:44:15