> I have a template stored in a database which contains variables.  Then,
> in a separate file, I have the variables set, and I call the template and
> it through eval().  Unfortunately, it only is parsing a few of them.
> somebody take a look and give me some input?

Here's what my template table looks like:

CREATE TABLE templates (
  id tinyint(4) unsigned NOT NULL auto_increment,
  name varchar(16) NOT NULL default '',
  template text NOT NULL,
  PRIMARY KEY  (id),
  UNIQUE KEY name (name)

Then here is my template function that preps the data for use with eval():

function template($name, $set="main"){
global $tb_templates;
$sql = "
  name = '$name'
if($query = sql_query($sql)){
  $array = sql_fetch_array($query);
  $template = str_replace("\\'","'",addslashes($array["template"]));
 } else {
  $template = $name . " template not found.";
return $template;

Then here is how to use eval() properly:

$template_name = template("template_name");
eval("\$template_name = \"$template_name\";");

This will parse all your $vars you store in the templates.

Greg Donald - http://destiney.com/
http://phprated.com/ | http://phplinks.org/ | http://phptopsites.com/

PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to