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