On Thu, May 06, 2004 at 11:10:17AM -0400, Paul Chvostek wrote: > 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. >
you can make the .* less greedy... $text = preg_replace('/<!--.*?-->/', '', $text); - rob -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php