ONJava.com -- The Independent Source for Enterprise Java
oreilly.comSafari Books Online.Conferences.


AddThis Social Bookmark Button
  PHP and Heredocs
Subject:   Why not use php-style instead of perlish (2)?
Date:   2003-04-12 11:34:46
From:   javajoint
Response to: Why not use php-style instead of perlish (2)?

Hi, I am Daniel Smith, the author:

I use heredocs SPECIFICALLY so that I do not have to write things such as:

FROM $table
WHERE field='1' ";

Which introduces a new level of quoting.

As far as reading complete templates into a variable, so that the template is free of PHP assignment statements.. Yes, that is true. It's a little more work, in a sense, if there is a middle section of the template that gets repeated.. it has to be broken out (via HTML comments or otherwise) so that it gets assigned to a different variable (or element in an associative array)

In other words, if you have a template of head, middle, and tail sections, you can break them up into seperate heredocs, or you can read a straight HTML file in and muddle through it, breaking up the sections afterward. Think of the middle section as any variable number of results (a table, a collection of photos, etc.)

You may want to take a look at my example demo file.
It is at: http://www.onlamp.com/php/2003/04/10/examples/hd-demo-1.0.tgz

as an aside: I did not get into caching in my article, but it is something I am working on for my project. I don't want to simply read in templates for every invocation if I don't need to.

The reason I approached things this way in the first place was because I wanted to keep my package as self-contained as possible (fewer dependencies for future admins to deal with), but I also wanted to handle different languages and interfaces.

Daniel Smith

1 to 1 of 1
  1. Why not use php-style instead of perlish (2)?
    2003-04-15 03:32:34  anonymous2 [View]

    • Why not use php-style instead of perlish (2)?
      2003-04-15 09:48:25  Daniel Smith | [View]

1 to 1 of 1