Re: strip comments from HTML?

From: Date: Thu, 06 May 2004 08:28:07 +0000
Subject: Re: strip comments from HTML?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-185501@lists.php.net to get a copy of this message
--- Justin French <justin@indent.com.au> wrote: > Hi, > > This isn't working: > $text = preg_replace('/<!--(.*)-->/','',$text); > > Can someone advise what characters I need to escape, > or whatever to get > it going? > > TIA > > --- > Justin French > http://indent.com.au > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > Hi, You must escape "-" (minus sign) because is a meta-character for regular expressions. See http://www.php.net/manual/en/pcre.pattern.syntax.php. Your line of code might be: <CODE> $text = preg_replace('/<!\-\-(.*)\-\->/','',$text); </CODE> 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. HTH Marius __________________________________ Do you Yahoo!? Win a $20,000 Career Makeover at Yahoo! HotJobs http://hotjobs.sweepstakes.yahoo.com/careermakeover

« previous php.general (#185501) next »