Re: strip comments from HTML?

From: Date: Thu, 06 May 2004 15:10:17 +0000
Subject: Re: strip comments from HTML?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-185531@lists.php.net to get a copy of this message
On Thu, May 06, 2004 at 03:02:16PM +1000, Justin French wrote: > > This isn't working: > $text = preg_replace('/<!--(.*)-->/','',$text); > > Can someone advise what characters I need to escape, or whatever to get > it going? It's not a matter of escaping. You're matching too much with the ".*". If you're sure you won't have any right-point-brackets inside comments, you can use something like: $text = ereg_replace("<!--[^>]*-->","",$text); Accurately matching comments in an extended regular expression is tricky though. The only thing you can really *negate* in an ereg is a range, not an atom. And the close of the comment can't be prepresented as a range, since it's multiple characters. Not to say it can't be done. I just can't think of how at the moment. :) -- Paul Chvostek <paul@it.ca> it.canada http://www.it.ca/ Free PHP web hosting! http://www.it.ca/web/

« previous php.general (#185531) next »