Keef has asked for the wisdom of the Perl Monks concerning the following question:

I've been working on a script that allows users to login and post news to my website. Well I've run into a problem. For some reason, after the article is previewed, or it's editied, several
's are added to the end of the post. I'm not sure if this is a form/script error or if users are just habitually hitting return when they're done typing out their post. Anwyay, I need a way to remove these extra
's at the end of the post. Is there an easy way to do that?

Replies are listed 'Best First'.
Re: Stripping Trailingbr's
by dvergin (Monsignor) on Apr 05, 2001 at 06:45 UTC
    $string =~ s/(<br>)+$//i;
Re: Stripping Trailingbr's
by Xxaxx (Monk) on Apr 05, 2001 at 12:16 UTC
    If you're including the input text be sure to run it through several fairly severe cleansings. You may want to strip any javascript, forms, ssi, applets and other goodies not desired. In fact if you're just looking for text perhaps stripping all tag might help.
    $textin =~ s/<[^>]*>//sg; ## strip normal tags $textin =~ s/^[^>]*>//sg; ## strip sneaky left over stuff $textin =~ s/<[^<]*$//sg; ## strip sneaky left over stuff
    That should get rid of most attacks to your script.
    Of course you can always just strip forms, ssi, etc. and leave normal tags alone. It all depends on how severe you feel you need to be -- or can afford.

    Claude

Re: Stripping Trailingbr's
by Caillte (Friar) on Apr 05, 2001 at 16:30 UTC

    If the <br> tag is all that is on the line then $line =~ s/^<br>$//i; will kill it. $line =~ s/^\s*<br>\s*$//i; would remove a tag that is only surrounded by whitespace.

    If you want to remove a particular tag/sets of tage from the entire document, take a look at HTML::Filter. It would seem to do some quite interesting things.

    $japh->{'Caillte'} = $me;

Re: Stripping Trailingbr's
by Keef (Sexton) on Apr 05, 2001 at 06:36 UTC
    I'm sorry, that was <br>'s.