NYCPHP Meetup

NYPHP.org

[nycphp-talk] heredoc string formatting question

edward potter edwardpotter at gmail.com
Sun Aug 13 21:41:51 EDT 2006


The heredoc things make your code formatting look like crap.  You can
never indent properly.

Why, O' why does not php after all these years use the ELEGANT way
that perl uses the qq|blah,blah", ', $a, |  way of doing things?

I hate the mix of double quote, single quotes, back slashes, heredoc,
etc.  Just wondering? (sorry,kinda of anal about this, your source
code should look elegant, that's the deal with me!)  I hate to see a
mix of backslashes and quotes. Yuck!

"The qq Function for Long Strings in Perl
If you write CGI programs in Perl, you probably find yourself using a
lot of long print statements for outputting HTML. HTML uses a lot of
double quotes, so it's better if you don't have to escape every " you
use. You can accomplish this with the qq function, which will
interpolate all variables but ignores double quotes."

http://www.devx.com/tips/Tip/5557

:-) ed



On 8/10/06, Cliff Hirsch <cliff at pinestream.com> 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
> _______________________________________________
> 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
>
>
>



More information about the talk mailing list