Re: ereg() problem

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

 




On Jan 31, 2007, at 8:13 AM, Jim Lucas wrote:

jekillen wrote:
Hello php list;
I am having trouble with ereg().
The following is the problem code
$x = ereg("<route name='$to' x='../(.*)/in' rec='.*' />", $get_route, $m);
do we need to break out of the text to include the $to variable??
The $to variable is what I use to id the tag to get the path from, it is
critical. It is like answering the question 'What is Joe's address?'
Joe in this example is the $to variable.


testing $route I get:
do you mean $get_route?
No, I mean $route after I have assigned $m[1] to it;

$route = $m[1];
print $route.'<br>';
jk/in' rec='a_378e6dc4.xml' /> (out put of print)
Is this an example of th input?
This is what the regular expression (.*) is matching
in the tag. It will have a steadily increasing number
of tags in the above pattern and nothing else (accept
for opening and closing xml tags.

What does an actual line of $get_route look like?
$get_route is what was read from the XML file.
It will have a steadily increasing number
of tags in the above pattern and nothing else (accept
for opening and closing xml tags.


do a var_dump($m); and show output
The problem is that the regex is missing the closing single quote and
matching to the end of the tag instead of just matching what is between
the  parenthesis.

jk is all I am looking for but
is it greed that is missing the
forward slash and the single quote?
It seems like every time I do this I have to monkey around
with it until I get what I want. 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 am using php v5.1.2 with Apache 1.3.34
Thanks in advance.
JK

or better yet, try this

I am assuming on the actual structure of $get_route but the following return to me $match[1] = '../jk'

$to = 'something';
$get_route = "<route name='something' x='../jk/in' rec='998asdf' />";
preg_match("|<route name='".$to."' x='(\.\./.*)/in' rec='.*' />|", $get_route, $matches);
var_dump($matches);
O.K. thanks, $m[0] is supposed to have the whole match and $m[1...n] is supposed to
contain the matches made by each set of parenthesis.
Does anyone know or understand the concept of greed in regular
expressions, and how to turn it off in php? That is all I am asking for.
JK

--
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