Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: How to remove HTML tags from text

by pelagic (Curate)
on Feb 04, 2005 at 11:48 UTC ( #428019=note: print w/ replies, xml ) Need Help??


in reply to How to remove HTML tags from text

One (of many) possibilities is to remove whatever there is between "<" and ">" no matter whether it's really HTML. This could be achieved easily with Text::Balanced's "extract_bracketed".


pelagic


Comment on Re: How to remove HTML tags from text
Re^2: How to remove HTML tags from text
by nejcPirc (Acolyte) on Feb 04, 2005 at 11:54 UTC
    Something like this?
    $data=~s/<.*?>//g; $data=~s/&lt.*?&gt//g;
      Text::Balanced does it properly even if there is some funny stuff between the brackets. Look into the documentation for more info. But of course you can also use some regex to remove the strings in a simple way.

      pelagic
      nope.
      $data = <<_END_; <script language="JavaScript"> alert("Boo!") </script > _END_
      A /s modifier would help a little, but doesn't solve everything. Eg, what about this tag?
      $data = qq{ <img src="hello.jpg" alt="x>y" width="60" height="60" /> } +;

      Lesson: never treat HTML parsing as a "back of an envelope" exercise :)

      cLive ;-)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2014-11-24 04:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (135 votes), past polls