Problem matching group inside another group
Posted: Sat May 03, 2008 7:41 am
hello,
i have an url which contains variable names and i want to parse it, so that these variable names are replaced with real --variables (hope you get what i mean). the problem comes when the variable inside the url is actually an array. It seems you can't match this array and then print out its value by a variable variable. Example:Won't work ($$match doesn't seem to have any value).
So I thought, let's retreive the name of the array and the name of every field. Then maybe oyu could 're-create' the array somehow. But I can't get the regex to work. This is the current expression: Which gives the output:
and to clarify: the output I would like it to be is rather something like the following:
Any help with getting this to work would be great.
thanks!
i have an url which contains variable names and i want to parse it, so that these variable names are replaced with real --variables (hope you get what i mean). the problem comes when the variable inside the url is actually an array. It seems you can't match this array and then print out its value by a variable variable. Example:
Code: Select all
$url = "http://example.com/%test['field1']['feild2']['field3']%";
preg_match_all("/%(.+?)%/", $url, $matches, PREG_PATTERN_ORDER);
foreach($matches[1] as $match)
$url = preg_replace("/%" . preg_quote($match) . "%/", $$match, $url);
So I thought, let's retreive the name of the array and the name of every field. Then maybe oyu could 're-create' the array somehow. But I can't get the regex to work. This is the current expression:
Code: Select all
/%([a-zA-Z|0-9]+?)(\['([a-zA-Z|0-9]+?)'\])*%/Code: Select all
Array
(
[0] => Array
(
[0] => %test['field1']['feild2']['field3']%
)
[1] => Array
(
[0] => test
)
[2] => Array
(
[0] => ['field3']
)
[3] => Array
(
[0] => field3
)
)Code: Select all
Array
(
[0] => Array
(
[0] => %test['field1']['feild2']['field3']%
)
[1] => Array
(
[0] => test
)
[2] => Array
(
[0] => [b]field1[/b]
)
[3] => Array
(
[0] => [b]field2[/b]
)
[4] => Array
(
[0] => field3
)
)thanks!