in reply to Removing HTML tags from a sting

Rather than removing the tags, you could easily use HTML entity encoding to make them appear literally as the user typed them:

use HTML::Entities; print encode_entities("<b>hi</b>"); &lt;b&gt;hi&lt;/b&gt;

    -- Chip Salzenberg, Free-Floating Agent of Chaos

Replies are listed 'Best First'.
Re: Re: Removing HTML tags from a string
by newrisedesigns (Curate) on May 20, 2002 at 16:58 UTC

    wouldn't just a simple

    foreach (@line){ $_ =~ s/\</\&lt\;/g; $_ =~ s/\>/\&gt\;/g; }

    work just as well?

    John J Reiser
    newrisedesigns.com
      Well, if that's what I meant, I probably would have typed something like this:

      for (@line) { s/</&lt;/g; s/>/&gt;/g; }

      But to answer your question: It's actually less brain drain to use a tested and complete module than to write equivalent code -- especially when the code isn't equivalent at all.... Or were you under the impression that the only dangerous characters for HTML rendering are "<" and ">"?

          -- Chip Salzenberg, Free-Floating Agent of Chaos