Re: variable placeholders in a text file
| From: | tamouse mailing lists | Date: | Tue, 01 Jan 2013 05:00:26 +0000 |
| Subject: | Re: variable placeholders in a text file | ||
| References: | 1 2 3 4 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-319990@lists.php.net to get a copy of this message | ||
On Mon, Dec 31, 2012 at 5:47 PM, Stephen <stephen-d@rogers.com> wrote:
> The common stuff for every page is defined in the file "include.php". I
> define the variable $markup in that file.
>
> Here is the definition for $markup
>
> $markup=<<<HEREDOC
[[snippy]]
> HEREDOC;
>
> By using require_once instead of fopen and fread, I have simpler code and
> PHP evaluates the embedded variables in $markup without any need to use
> string functions.
While using the *_once works in many cases, if you're doing a mass
mailing kind of thing, you want to use the standard include/require so
you can re-include it as your variables change:
foreach ($customers as $customer) {
$fullname = $customer['fullname'];
$address = $customer['address'];
// and so on
include("mailing.php");
process($mailing,$customer);
}
where mailing.php defines the $mailing variable as the content that
got included and substituted.
(Back before I came up with this, I was starting off in the same place
as the OP -- and then I just realized "wait --- PHP *IS* a templating
system!" a voila)