What is PHP strip_tags() Perl quivalent?

This Comment will be submitted for moderation and will not be accessible to other users until it has been approved.


43 points

Like the previous PHP Strip_tags() javascript equivalent question, I am looking for PHP strip_tags() Perl equivalent? I have to stip all html tags from content in Perl.



10 points

Use Perl's CPAN Strip module as indicated below:

HTML::Strip - Perl extension for stripping HTML markup from text.

 use HTML::Strip;
 
  my $hs = HTML::Strip->new();
 
  my $clean_text = $hs->parse( $raw_html );
  $hs->eof;

Anonymous's picture
Created by Anonymous
2 points

CPAN strip module has the limitation that despite only outputting one space character per group of tags, and avoiding doing so when tags are bordered by spaces or the start or end of strings, HTML::Strip can often output more than desired; such as with the following HTML:

     <h1> HTML::Strip </h1> <p> <em> <strong> fast, and brutal </strong> </em> </p>

This gives the following output:
     HTML::Strip    fast, and brutal   

Thus, you may want to post-filter the output of HTML::Strip to remove excess whitespace (for example, using tr/ / /s;). (This has been improved since previous releases, but is still an issue)

Anonymous's picture
Created by Anonymous

Post Comment

  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <c>, <cpp>, <drupal5>, <drupal6>, <java>, <javascript>, <php>, <python>, <ruby>. Beside the tag style "<foo>" it is also possible to use "[foo]". PHP source code can also be enclosed in <?php ... ?> or <% ... %>.