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

Bob Patin bob at patin.com
Fri Feb 19 09:19:36 MST 2010


Jonathan,

I'm not sure how 

Dear <<name>>,

How's the weather in <<city>>?

is any different from doing this:

Dear <$php echo $name; ?>,

How's the weather in <?php echo $city ?>?

Seems like just as much work either way, and the latter has worked just fine for me. I'm not a fan of constructing HTML in my PHP code; I insert PHP in my HTML, which I think is easier to read...

Bob Patin



Longterm Solutions
bob at longtermsolutions.com
615-333-6858
http://www.longtermsolutions.com
iChat: bobpatin
FileMaker 9 & 10 Certified Developer
Member of FileMaker Business Alliance and FileMaker TechNet
--
Expert FileMaker Consulting 
FileMaker Hosting for all versions of FileMaker
PHP • Full email services • Free DNS hosting • Colocation • Consulting


On Feb 19, 2010, at 8:26 AM, Jonathan Schwartz wrote:

> 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
> _______________________________________________
> FX.php_List mailing list
> FX.php_List at mail.iviking.org
> http://www.iviking.org/mailman/listinfo/fx.php_list

-------------- next part --------------
Skipped content of type multipart/related


More information about the FX.php_List mailing list