"This is a string stored on a MySQL database and my name is {%firstname%} and I am neat"
my goal is to be able to use that template so that I can query my database and have it return:
"This is a string stored on a MySQL database and my name is Burrito and I am neat"
here's how I'm doing it:
Code: Select all
$result = mysql_query("select * from nlms_leads where id = ".$_POST['id'])
or die(mysql_error());
$row = mysql_fetch_assoc($result);
$gettemp = mysql_query("select * from nlms_user_template where id = ".$_POST['temp'])
or die(mysql_error());
$gttemp = mysql_fetch_assoc($gettemp);
$pattern = "/\{%(\w*)%\}/";
$body = preg_replace($pattern,$row["$1"],$gttemp['body']);Note: I have tried all of these derivations of my preg_replace all with no luck:
Code: Select all
$body = preg_replace($pattern,$row[$1],$gttemp['body']);
$body = preg_replace($pattern,$row[${"1"}],$gttemp['body']);
$body = preg_replace($pattern,$row[\\1],$gttemp['body']);
$body = preg_replace($pattern,$row["\\1"],$gttemp['body']);