Re: strip comments from HTML?

From: Date: Thu, 06 May 2004 12:20:34 +0000
Subject: Re: strip comments from HTML?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-185518@lists.php.net to get a copy of this message
From: "Justin French" <justin@indent.com.au> > This isn't working: > $text = preg_replace('/<!--(.*)-->/','',$text); > > Can someone advise what characters I need to escape, or whatever to get > it going? $text = preg_replace('/<!--.*-->/su','',$text); The 's' modifier will allow the expression to pick up multi-line comments by allowing the dot character to match newlines and the 'u' modifier makes it 'ungreedy', so that if you have <!-- comment 1 --> HTML example <!-- comment 2 --> only the comments themselves are matched and not everything from the first "<!--" to the last "-->". ---John Holmes...

« previous php.general (#185518) next »