Ok, i know how to use strip_tags, please don't point me to the PHP function page.

What I CAN'T figure out is what tag to put in to allow HTML comments. I use comments in some tricky ways in a project I am doing to allow calls to PHP functions in a very secure method (but alas that is the topic of another discussion).

So far I have tried:

$comments = strip_tags($comments, '<!-- -->');
$comments = strip_tags($comments, '<!-- >');
$comments = strip_tags($comments, '<!>');

And about a dozen other permutations, all of them seem to just strip the comments, sometimes just leaving the "!"....

Any advice, I have search everything I can think to search and am just plain stuck....

Thanks...

    That's a little bug in PHP. Here's what I'd recommend doing, since I don't know of an actual way around it: replace all the <!-- and -->s with something like {!-- and --}, then after you strip_tags, replace all the {!-- and --}s with <!-- and -->.

      Thanks for the hint, I came up with a hack based upon your advice, but doesn't that seem like kinda of a big bug that you'd think would be fixed in PHP 4.3.0 by now???

      Anyway, I love PHP, a bug here or there is no worry!

        I'd probably start off the way you did, maybe testing <!--> (no space) as well, but if everything fails what about stripping the tags yourself?

        something simple like
        $text = preg_replace('/<[!][>]*>/', '', $text);
        may do I think, and there are lots of other examples in the user comments (though I haven't seen one dealing with your particular problem).

          Write a Reply...