mouldy_punk
08-15-2005, 03:56 PM
Hey, I have this in a database:
<html>
<title>
$glob['sitename']
</title>
and I'm trying to get it to echo properly, so it'll parse the HTML as HTML and the variable will show it's value. Well, the problem I have is that I can do that, but not if it's coming from the database.
What happens is if I do:
$template = "
<html>
<title>
$glob['sitename']
</title>";
eval('$template = "$template";');
echo $template;
It parses it all fine. But if I get the template from teh database and run it through eval() it doesn't parse it properly.
Here's the whole function:
function get_template($part){
global $glob;
$query = mysql_query(" SELECT * FROM `$glob[prefix]-templates` WHERE `section`= '$part' ") or die(mysql_error());
$row = mysql_fetch_array($query);
$section = $row['section'];
$original = $row['original'];
$modified = $row['modified'];
if($row == FALSE){
die('Error getting template from database');
}
if($modified === ''){
$template = $original;
}else{
$template = $modified;
}
eval('$template = "$template";');
echo $template;
};
That will parse the HTML properly, but the title will be $glob['sitename'] - not the value of the variable. Which is really odd because if I just set $template to the stuff that's in the database, it works. It's just after I get it from the database that it doesn't.
Any help is appriciated :)
<html>
<title>
$glob['sitename']
</title>
and I'm trying to get it to echo properly, so it'll parse the HTML as HTML and the variable will show it's value. Well, the problem I have is that I can do that, but not if it's coming from the database.
What happens is if I do:
$template = "
<html>
<title>
$glob['sitename']
</title>";
eval('$template = "$template";');
echo $template;
It parses it all fine. But if I get the template from teh database and run it through eval() it doesn't parse it properly.
Here's the whole function:
function get_template($part){
global $glob;
$query = mysql_query(" SELECT * FROM `$glob[prefix]-templates` WHERE `section`= '$part' ") or die(mysql_error());
$row = mysql_fetch_array($query);
$section = $row['section'];
$original = $row['original'];
$modified = $row['modified'];
if($row == FALSE){
die('Error getting template from database');
}
if($modified === ''){
$template = $original;
}else{
$template = $modified;
}
eval('$template = "$template";');
echo $template;
};
That will parse the HTML properly, but the title will be $glob['sitename'] - not the value of the variable. Which is really odd because if I just set $template to the stuff that's in the database, it works. It's just after I get it from the database that it doesn't.
Any help is appriciated :)
