NYCPHP Meetup

NYPHP.org

[nycphp-talk] heredoc string formatting question

csnyder chsnyder at gmail.com
Thu Aug 10 17:40:00 EDT 2006


On 8/10/06, Cliff Hirsch <cliff at pinestream.com> wrote:

> Thoughts? Comments?

There are two potential gotchas with the heredoc approach:

1) make sure your editor is using the correct newline character(s)
2) make sure your editor doesn't _ever_ accidentally indent the "EOT;"

The second one is a big deal.

There's really no reason not to just quote the whole thing, is there?

$body = "Hi $name,
Thanks for joining.
$somevariable
Bye!";

Or, if you have an editor that does auto-indent:

$body = "Hi $name,".NEWLINE
             ."Thanks for joining.".NEWLINE
             .$somevariable.NEWLINE
             ."Bye!";

... though I gues the concatenating dots are easy to miss.

A template system is the way to go if you have to build more than a
few of these, or if you need to generate complex (multi-part html)
messages.

-- 
Chris Snyder
http://chxo.com/



More information about the talk mailing list