hi,
this function is supposed to take one input ($oldtext) and parse it for variables
variables are defined as {%variablename} inside the templates
what i need it to do is replace {%variablename} with whatevers inside the PHP variable name called $variablename
since the function's inside a class, the variable will also have to be globalised before being used...
this is the code i've got so far... (doesn't work lol)
function variable_parse($oldstring)
{
$numvars = substr_count("$oldstring", "{%");
if($numvars==0)
{
$newvar = $oldstring;
}
while($numvars > 0)
{
for($i=0;$i<$numvars;$i++)
{
$posstart = strpos($oldstring, "{%");
$posstop = strpos($oldstring, "}");
$length = $posstop - $posstart + 1;
$untrimmedvariablename = substr("$oldstring", $posstart, $length);
$varname = substr("$untrimmedvariablename", 2, -1);
global $$varname; //globalise $$varname (makes a variable out of variable name found above {%whatever} and globalises it)
echo "Varname: $varname<br>Globals varname: " . $GLOBALS[$varname];
$newvar = str_replace($untrimmedvariablename,$GLOBALS[$varname],$oldstring);
$oldstring = $newvar;
}
$numvars = substr_count("$oldstring", "$startbit");
}
return $oldstring;
}