Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Small HTML parser

by Yohimbe (Pilgrim)
on Aug 08, 2000 at 05:33 UTC ( [id://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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2024-04-24 01:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found