Hello guys, You know the function strip_tags() right? It removes all the tags and the content inside them, is there any way that I can remove tags but leaving the content inside them? Thank you, -AT-XE
function strip_tags leaves the data data intact, but just removes the usual tags. You might have error somewhere, see example below please: <? $str = "<b>Hi am Vooler</b>, and am a php teacher."; $str = strip_tags($str); echo $str; //printed out: Hi am Vooler, and am a php teacher. ?> PHP: Or show me your code. regards
There must be something wrong with your code, AT. strip_tags() won't wipe out your content just like that.
Hmm, found a solution and (!!!) it removes javascript too: <?php $file = file_get_contents('http://www.google.com/'); function html2txt($document){ $search = array('@<script[^>]*?>.*?</script>@si', // Strip out javascript '@<style[^>]*?>.*?</style>@siU', // Strip style tags properly '@<[\/\!]*?[^<>]*?>@si', // Strip out HTML tags '@<![\s\S]*?--[ \t\n\r]*>@' // Strip multi-line comments including CDATA ); $text = preg_replace($search, '', $document); $txt = str_replace("\r\n", '', $txt); return $text; } echo html2txt($file); ?> PHP:
If strip_tags() gets rid of your content, your tags are probably miswritten -- unclosed quotes on a tag attribute could conceivably do that.
Well, I will suggest use the standard one as azizny is suggesting as well as corruption of returned data is unexpected on different forms of input as chaosprime quoted, your script is making call to 3 functions practically. 1.html2txt -> 2.preg_replace -> 3.str_replace Comparing precompiled function strip_tags is inline and filters internally rather than making call to companion functions. For the time being, it is ok, but when you get into large applications, where you have to keep structure of applciation stable, you will be feeling need of what is being said. Just a thought. regards
The problem with strip tags is that it leaves the content, yes but it allows some style information to pass, sometimes and javascript.