Re: Re: strip comments from HTML?

From: Date: Thu, 06 May 2004 16:47:10 +0000
Subject: Re: Re: strip comments from HTML?
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-185541@lists.php.net to get a copy of this message
On Thu, May 06, 2004 at 11:26:34AM -0400, Rob Ellis wrote: > > > > $text = ereg_replace("<!--[^>]*-->","",$text); > > you can make the .* less greedy... > > $text = preg_replace('/<!--.*?-->/', '', $text); Interesting to know. My preg-foo is limited; I came at PHP from a background of awk and sed, so when I regexp, I'm a little more traditional about it. Interestingly, from a shell: $ text='one <!-- bleh --> two\nthree <!-- blarg -->four\n' $ printf "$text" | sed -E 's/<!--([^-][^-]?[^>]?)*-->//g' one two three four which is the same behaviour as PHP. But that still doesn't cover multi-line. PHP's ereg support is supposed to, but doesn't work with this particular substitution: $text="one <!--bleh\nblarg -> two\n"; print ereg_replace("<!--([^-][^-]?[^>]?)*-->", "",$text); returns one <!--bleh blarg -> two But we know it really does support multiline, because: $text="aaaabb\nbbcccc"; print ereg_replace("[^ac]","",$text); returns aaaacccc So ... this is interesting, and perhaps I'll investigate it further if the spirit moves me. ;-) -- Paul Chvostek <paul@it.ca> it.canada http://www.it.ca/ Free PHP web hosting! http://www.it.ca/web/

« previous php.general (#185541) next »