in reply to Removing characters

Sorry.... I was clear. This is was I want:

I want to remove all html tags entered by a user. This is the code I have (which works), but I need to know what to put where it says HERE

$string =~ s/<HERE*>//eg;

So, what goes between the brackets, that would mean erase any html tags from the string?

Replies are listed 'Best First'.
RE: Re: Removing characters
by btrott (Parson) on Apr 21, 2000 at 01:33 UTC
    That's tricky, trying to remove HTML; but you can try to do it w/ a regex, in which case you'll want something like this:
    $string =~ s/<[^>]*>//gs;
    Or you could use
    $string =~ s/<.*?>//gs;
    The first looks between < and > for any character that's not a >, and the second looks from the first < until it finds a > (the '?' makes it a non-greedy match).

    You don't need the "e" modifier, because you're not executing any code on the right-hand side of the substitution. And you should use the "s" because HTML tags can span multiple lines, so you want the '.' to match newlines.

    If you find that the regex really isn't working well enough, take a look at HTML::Parser, HTML::TokeParser, and HTML::FormatText.