in reply to Stripping HTML tags efficiently
EDIT: As per Crian's comment, the above should be print join "\n", m/<.*?>/sg; instead.use strict; use warnings; read(DATA, $_, 1024); print join "\n", m/<.*?>/g; __DATA__ Once <a href="foo.html">upon</a> a time there was a <font color="#FF0000">CODE <b>RED</b></font> situation.
Or a line by line version, if you're working with large files:
This is not really a robust method, however, and you're probably better off using a library unless your needs are simple and you're sure the tags are formatted properly.use strict; use warnings; while (<DATA>) { print $&."\n" while m/<.*?>/g; } __DATA__ Once <a href="foo.html">upon</a> a time there was a <font color="#FF0000">CODE <b>RED</b></font> situation.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Stripping HTML tags efficiently
by Crian (Curate) on Dec 10, 2004 at 11:13 UTC | |
| |
Re^2: Stripping HTML tags efficiently
by Your Mother (Archbishop) on Dec 10, 2004 at 18:48 UTC |