[nycphp-talk] heredoc string formatting question
Donald J Organ IV
dorgan at optonline.net
Thu Aug 10 17:29:24 EDT 2006
Why not have templates such as files that have all this stuff in it such as:
Hi %%name%%. Welcome message
%%body%%
This could be the footer
You would have that in a file then use file_get_contents() to put it all
into one big string then you could use say
str_replace( '%%name%%', $name, $contents );
str_replace( '%%body%%', $name, $contents );
you could even use an html file as your template. I do this all that time.
Cliff Hirsch wrote:
>
> I currently generate email bodies as follows:
>
> $body = "Hi $name. Welcome message.".NEWLINE;
>
> $body .= NEWLINE;
>
> $body .= $somevariable;
>
> $body .= NEWLINE;
>
> $body .= “More body”;
>
> It works. It’s fairly easy on the eyes. But it’s laborious – and
> hardcoded.
>
> I’m thinking of switching to:
>
> $body = <<<EOT
>
> Hi $name. Welcome message.
>
> $somevariable
>
> More body.
>
> EOT;
>
> Both approached are hard coded, which has major limitations. I’m a bit
> concerned about how line breaks are interrupted by heredoc and
> downstream email clients.
>
> The other alternative would be a template-driven database approach,
> but than the body “variable” would have to be parsed every time.
>
> One though I had was to use Smarty to generate tpl files for the email
> bodies, letting it do the parsing and compiling.
>
> Thoughts? Comments?
>
> Cliff
>
> _______________________________
> *Pinestream Communications, Inc.*
> Publisher of /Semiconductor Times/ & /Telecom Trends/
> 52 Pine Street, Weston, MA 02493 USA
> Tel: 781.647.8800, Fax: 781.647.8825
> http://www.pinestream.com <http://www.pinestream.com/>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> New York PHP Community Talk Mailing List
> http://lists.nyphp.org/mailman/listinfo/talk
>
> NYPHPCon 2006 Presentations Online
> http://www.nyphpcon.com
>
> Show Your Participation in New York PHP
> http://www.nyphp.org/show_participation.php
>
> ------------------------------------------------------------------------
>
> No virus found in this incoming message.
> Checked by AVG Free Edition.
> Version: 7.1.405 / Virus Database: 268.10.8/415 - Release Date: 8/9/2006
>
More information about the talk
mailing list