Re: ereg() problem

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, January 30, 2007 8:36 pm, jekillen wrote:
> I am having trouble with ereg().
> The following is the problem code
> $x = ereg("<route name='$to' x='../(.*)/in' rec='.*' />", $get_route,
> $m);
> testing $route I get:
> $route = $m[1];
> print $route.'<br>';
> jk/in' rec='a_378e6dc4.xml' /> (out put of print)
> jk is all I am looking for but
> is it greed that is missing the
> forward slash and the single quote?

No, it's that you put the parens () around only the .* and not around
what you wanted:
ereg("<route name='$to' x='\\.\\.(.*/in') rec='.*' />", ...

> It seems like every time I do this I have to monkey around
> with it until I get what I want.

Join the club. :-)

You may want to consider a couple actions:
  Switch to PCRE http://php.net/pcre

It's better documented, less confusing, faster, and just better all
around.

Download and play around with "The Regex Coach" which provides a
visual feedback on what happens when you change the #$^%& inside your
pattern.

> I have even changed the
> formatting of files just so a regular expression would
> work without this sort of trial and error.
> Is there a way I can turn off greed in php's regex?

I haven't used ereg in so long, I can't answer this for ereg.
In PCRE, you use tack on 'U' after your end patter delimiter.

-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux