[FX.php List] Seeking improved "mail merge"

Jonathan Schwartz jschwartz at exit445.com
Fri Feb 19 07:26:28 MST 2010


Hi Folks,

I'm looking to improve on my present technique of embedding variables 
within a text string, such as one might do with an email merge.

I want to allow the admin end users to create custom email messages 
in text strings, embedding pre-established tags that will resolve to 
actual values, such as : "Dear {firstname},  Your order {OrderNumber} 
has shipped."

Up to this time, I have hard-coded the $variables in a text string 
and used a series of string replace commands...which wont' work in 
this new environment I wan to create.

So, I am looking for the right php script to do this substitution, 
given there there is a list of a dozen or so possible variables that 
*could* get substituted into the text string, depending whether or 
not the {tag} is present in the body of the test string created by 
the admin user. Of course, I will have the $variables from the db 
set, so $namefirst will provide a value for {firstname}, etc.

I've been looking at at all the preg options, and have not been able 
to figure out which way to go.

In essence, I need a function that scans the email text string for 
known {tags} and substitutes values as they are matched. Here is my 
guess how it could work.  If this approach is OK, the key question is 
which function to use for the "if({tag} is found in the string" part.

CODE GUESS....

$textbody = "Dear {firstname} {lastname}.....";
$taglist= {'{firstname}', '{lastname}', ......);
$tagvalues = ('john', 'smith', ....);

foreach($taglist)
{

if( {tag}  is found in  $textbody, substitute $tagvalue;
}

Any help?

Thx

Jonathan

-- 
Jonathan Schwartz
Exit 445 Group
jonathan at exit445.com
http://www.exit445.com
415-370-5011


More information about the FX.php_List mailing list