RTFM.
perldoc -q 'remove html'
How do I remove HTML from a string?
The most correct way (albeit not the fastest) is to use
HTML::Parser from CPAN. Another mostly correct way is to use
HTML::FormatText which not only removes HTML but also attempts
to do a little simple formatting of the resulting plain text.
Many folks attempt a simple-minded regular expression approach,
like s/<.*?>//g, but that fails in many cases because the
tags may continue over line breaks, they may contain quoted
angle-brackets, or HTML comment may be present. Plus, folks
forget to convert entities--like < for example.
Here's one "simple-minded" approach, that works for most files:
#!/usr/bin/perl -p0777
s/<(?:[^>'"]*|(['"]).*?\1)*>//gs
If you want a more complete solution, see the 3-stage striphtml
program in http://www.cpan.org/authors/Tom_Christiansen/scripts/striphtml.gz.
Also, with Super Search or Google, you can find hundreds of answers.
See also How (Not) To Ask A Question.
Juerd
# { site => 'juerd.nl', plp_site => 'plp.juerd.nl', do_not_use => 'spamtrap' }
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|