Re: strip comments from HTML?
| From: | David T-G | Date: | Thu, 06 May 2004 10:33:01 +0000 |
| Subject: | Re: strip comments from HTML? | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-185506@lists.php.net to get a copy of this message | ||
Marius, et al --
..and then Marius Dascalu said...
%
% --- Justin French <justin@indent.com.au> wrote:
% >
% > This isn't working:
% > $text = preg_replace('/<!--(.*)-->/','',$text);
..
%
% Hi,
Hello!
%
% You must escape "-" (minus sign) because is a
% meta-character for regular expressions. See
What? No.
% http://www.php.net/manual/en/pcre.pattern.syntax.php.
From that same link:
Part of a pattern that is in square brackets is called a "character
class". In a character class the only meta-characters are:
\
general escape character
^
negate the class, but only if the first character
-
indicates character range
]
terminates the character class
So you only have to worry about a minus if you're in a [a-z] range, and
even then you can put a minus in without having to resort to backslashes.
% Your line of code might be:
%
% <CODE>
% $text = preg_replace('/<!\-\-(.*)\-\->/','',$text);
% </CODE>
Then, again, it might not ;-)
%
% This line of code, if you are parsing HTML file row by
% row, strips only "one line" comments. Comments spanned
% on multiple lines are unaffected.
Agreed. Let's leave that to the student to work out, shall we? :-)
%
% HTH
%
% Marius
HTH & HAND
:-D
--
David T-G
davidtg@justpickone.org
http://justpickone.org/davidtg/ Shpx gur
Pbzzhavpngvbaf Qrprapl Npg!