Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

RE: BBS HTML fitler

by DrManhattan (Chaplain)
on Aug 07, 2000 at 17:55 UTC ( [id://26551]=note: print w/replies, xml ) Need Help??


in reply to BBS HTML fitler

Here's an example using HTML::TokeParser

#!/usr/bin/perl -w use strict; use HTML::TokeParser; # Regex representing the list of acceptable tags my $ok_stuff = qr/^(p|br|h.|font|pre)$/; # Some test html. my $html = "<p><br><h3><a href='evil.js'>Testing</a></h3></p>\n"; # Instantiate the TokeParser my $parser = new HTML::TokeParser (\$html); # Loop until all tokens are read while (my $token = $parser->get_token()) { # Immediately print any "text" token if ($token->[0] eq "T") { print $token->[1]; } # Check all other tokens against the regex before printing elsif ($token->[1] =~ $ok_stuff) { print $token->[$#{$token}]; } }

The above code prints out "<p><br><h3>Testing</h3></p>"

-Matt

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2024-04-19 23:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found