Hi,
I'm trying to parse a file/String and return variables and then replace them with their values.
it seemed to me to be a common request but cannot find out how to do it anywhere on the Web.
e.g.
$Text = "{Var} is what I want and {Foo}, but {NotThis} and {NotThisOne}";
//Ive worked out how to do it using
peg_match_all("/{.[\}]*})/",$Text,$matches);
//but not with the escaping of {}'s
//this will make $matches[1] = array({Var}", "{Foo}","{NotThis}","{NotThisOne}");
var_dump($matches[1]);
//I want $matches[1] to return only ("{Var},"{Foo}")
//I've come up with this: - works most times
preg_match_all("/(\{.(\})*\})/",$Text,$matches);
var_dump($matches[1]);
//but it will not work if the { is the first character or near the beginning of the string.
Please Help..
Thanx