Re: strip comments from HTML?

From: Date: Thu, 06 May 2004 11:41:14 +0000
Subject: Re: strip comments from HTML?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-185510@lists.php.net to get a copy of this message
--- David T-G <davidtg-php@justpickone.org> wrote: > 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! > > > ATTACHMENT part 2 application/pgp-signature K, my fault (but the script is functional in both variants - tested in SciTE). That is 2nd faulty response sended by me to list. At the 3rd I will unsubscribe :-) HAND __________________________________ Do you Yahoo!? Win a $20,000 Career Makeover at Yahoo! HotJobs http://hotjobs.sweepstakes.yahoo.com/careermakeover

« previous php.general (#185510) next »