Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Small HTML parser

by Yohimbe (Pilgrim)
on Aug 08, 2000 at 05:33 UTC ( #26720=perlquestion: print w/replies, xml ) Need Help??

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

Given an online commenting system similar to the monastery, and desiring flexibility, with security. I need a small that can take a snippet of html code and allow ONLY a short list of "approved" tags, ie, character formatting and linking only but no tables or blockquotes or javascript.
What I'm talking about starts with something like this:
sub cleanhtml ($) { my $dirty_html=shift; my @allowed_tags=qw(A B BR P I CODE PRE); and ends with: return $safe_html; }

Replies are listed 'Best First'.
Re: Small HTML parser
by lhoward (Vicar) on Aug 08, 2000 at 07:38 UTC
Re: Small HTML parser
by perlmonkey (Hermit) on Aug 08, 2000 at 06:35 UTC
    There has got to be a better way to do it, but this is a slow hack that will work:
    my $list = join('|', @allowed_tags); $dirty_html =~ s!<\s*/?\s*(\w+).*?>!($a,$b)=($&,$1); $a if $b =~ /^(?: +$list)$/!esg;
RE: Small HTML parser
by DrManhattan (Chaplain) on Aug 08, 2000 at 18:39 UTC

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://26720]
Approved by root
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (3)
As of 2022-09-30 12:41 GMT
Find Nodes?
    Voting Booth?
    I prefer my indexes to start at:

    Results (126 votes). Check out past polls.