Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Re: Strip HTML tags again

by Ovid (Cardinal)
on Jun 30, 2002 at 20:20 UTC ( #178410=note: print w/ replies, xml ) Need Help??

in reply to Strip HTML tags again

This problem looks tailor-made for my HTML::TokeParser::Simple module, when combined with HTML::Tagset. The following test will demonstrate:

#!/usr/bin/perl -w use strict; use HTML::TokeParser::Simple; use HTML::Tagset; my $html = <<'END_HTML'; <a href="mylink">text1</a> <this is normal text> END_HTML my $p = HTML::TokeParser::Simple->new( \$html ); while ( my $token = $p->get_token ) { next if ! $token->is_text and exists $HTML::Tagset::isKnown{ $token->return_tag }; print $token->return_text; }


<this is normal text>


Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.

Comment on Re: Strip HTML tags again
Download Code
Replies are listed 'Best First'.
Re^2: Strip HTML tags again
by Your Mother (Chancellor) on Mar 05, 2009 at 01:02 UTC

    ++ for the original. I'm posting an updated example because some changes to the module seem to have borked your example. This is an in place stripper--based on the one you posted--with the newer/working syntax.

    sub strip_html { my $renew = ""; my $p = HTML::TokeParser::Simple->new(\$_[0]); no warnings "uninitialized"; while ( my $token = $p->get_token ) { next if ! $token->is_text and exists $HTML::Tagset::isKnown{ $token->get_tag }; $renew .= $token->as_is; } $_[0] = $renew; }

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2015-11-25 04:35 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (670 votes), past polls