Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: HTML::Strip question--stripping only certain tags?

by bmann (Priest)
on Feb 01, 2006 at 23:05 UTC ( #527187=note: print w/ replies, xml ) Need Help??


in reply to HTML::Strip question--stripping only certain tags?

HTML::Scrubber lets you allow only selected tags. I lifted the following from the pod (slightly modified):

#!/usr/bin/perl -w use HTML::Scrubber; use strict; my $html = q[ <style type="text/css"> BAD { background: #666; color: #666;} </style> <script language="javascript"> alert("Hello, I am EVIL!"); </script> <HR> a => <a href=1>link </a> br => <br> b => <B> bold </B> u => <U> UNDERLINE </U> ]; # only allow the following tags my $scrubber = HTML::Scrubber->new( allow => [ qw[ p b i u hr br ] ] ) +; print $scrubber->scrub($html); __END__ Output: <hr> a => link br => <br> b => <b> bold </b> u => <u> UNDERLINE </u>
style, script and links are gone.


Comment on Re: HTML::Strip question--stripping only certain tags?
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://527187]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (11)
As of 2015-07-28 09:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (254 votes), past polls