Beefy Boxes and Bandwidth Generously Provided by pair Networks Bob
No such thing as a small change
 
PerlMonks  

Stripping Trailingbr's

by Keef (Sexton)
on Apr 05, 2001 at 02:35 UTC ( [id://69992]=perlquestion: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.

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 Keef (Sexton) on Apr 05, 2001 at 02:36 UTC
    I'm sorry, that was <br>'s.
Re: Stripping Trailingbr's
by dvergin (Monsignor) on Apr 05, 2001 at 02:45 UTC
    $string =~ s/(<br>)+$//i;
Re: Stripping Trailingbr's
by Xxaxx (Monk) on Apr 05, 2001 at 08: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 12: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;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://69992]
Approved by root
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.