Parse PHP from string
Posted: Thu Nov 13, 2008 5:55 am
Hi there.
Been searching around for good PHP help forums for a long time, let's hope this is the one that will bring me the most help.
Ok, well I'm developing a PHP template system, allowing the passing of variables and functions in its own unique way, similar to Smarty.
My issue at the moment, is preventing me from passing dynamic variables. Here is an example of a array call through the template system.
Now, as the profile/register fields are also dynamically called from the database, the nickname part must be able to be called via another variable, within a loop.
So, all in all, it splits at the dots and loops through them, appending the current key to the $echo variable.
But, my issue lies here:
The value of $var is register_{var} and I am trying to parse {var} to a normal variable to come from the key of a loop being processed.
If anyone could analyse the code and see if you could come up with a solution I'd be extremely grateful.
Thanks,
Nick.
Been searching around for good PHP help forums for a long time, let's hope this is the one that will bring me the most help.
Ok, well I'm developing a PHP template system, allowing the passing of variables and functions in its own unique way, similar to Smarty.
My issue at the moment, is preventing me from passing dynamic variables. Here is an example of a array call through the template system.
Code: Select all
[core.post.register_nickname]Code: Select all
$var_split = explode('.', $arg);
foreach($var_split as $var)
{
if($count == 0)
{
$echo = $this->vars[$var];
}
else
{
if($echo[$var])
{
$echo = $echo[$var];
}
else
{
if($var)
{
$echo = $echo['\'' . preg_replace('/{(.*?)}/i', "$\\1", $var) . '\''];
}
}
}
$count++;
}
But, my issue lies here:
Code: Select all
$echo = $echo['\'' . preg_replace('/{(.*?)}/i', "$\\1", $var) . '\''];If anyone could analyse the code and see if you could come up with a solution I'd be extremely grateful.
Thanks,
Nick.