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                                             <[EMAIL PROTECTED]>
  it.canada                                            http://www.it.ca/
  Free PHP web hosting!                            http://www.it.ca/web/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to