Re: [PHP4BETA] help with ereg - 2

From: Date: Wed, 22 Mar 2000 09:46:52 +0000
Subject: Re: [PHP4BETA] help with ereg - 2
References: 1  Groups: php.version4 
Request: Send a blank email to php-version4+get-12484@lists.php.net to get a copy of this message
Simple script: $ss="<A HREF=test.phtml>{THIS}</A>&nbsp;25{newsdate}"; eregi("{([^}]+)}",$ss,$regs); echo $ss."<BR>"; echo $regs[0]."<BR>"; In result: ss={THIS} 25{newsdate} regs[0]={THIS} Why? From PHP Manual : $regs[0] will contain a copy of string. ----- Original Message ----- From: Stanislav Malyshev <stas@zend.com> To: Vadim Tkachenko <vvtk@stealthcomp.com> Cc: php4beta <php4beta@lists.php.net> Sent: Wednesday, March 22, 2000 11:23 AM Subject: Re: [PHP4BETA] help with ereg > VT>> eregi("{(.+)}","Test string {one} and test line {two}",$regs) > VT>> return $regs[1]="one} and test line {two". > > That's because + is "greedy". You need to use "{([^}]+)}" or use > preg_match in non-greedy mode (or with non-greedy "+?" instead of "+"). > > -- > Stanislav Malyshev stas@zend.com > +972-3-6139665 >

« previous php.version4 (#12484) next »