On Thu, Aug 09, 2007 at 02:39:51PM -0700, Jim Lucas wrote:
> Rick Pasotto wrote:
>> Does php have a facility similar to python's stringIO?
>> What I'm wanting to do is similar to a mail merge. IOW, I know I can
>> create an include file like:
>> $out = <<<EOT
>> This is an example of $var1 and $var2.
>> EOT;
>> and then after assigning values to $var1 and $var2 include that file. I
>> can later use different values for $var1 and $var2 and get a different
>> $out with a second include.
>> Can I someout "include" a string instead of a file? Or maybe there is
>> some completely different way to do what I want.
> template.php
> <?php
>
> ob_start();
> echo "Hi, my name is {$first_name} {$last_name}.";
> return ob_get_clean();
>
> ?>
>
>
> This is two different ways you can do it, bases on your input data array 
> structure
>
> test.php
> <?php
>
> $values = array();
>
> $values[] = array('first_name' => 'Jim','last_name' => 'Lucas');
> $values[] = array('first_name' => 'James','last_name' => 'Lucas');
> $values[] = array('first_name' => 'Jimmy','last_name' => 'Lucas');
>
> foreach ($values AS $row) {
>       extract($row);
>       echo include 'template.php';
> }
>
> $values = array();
>
> $values[] = array('Jim','Lucas');
> $values[] = array('James','Lucas');
> $values[] = array('Jimmy','Lucas');
>
> list($first_name, $last_name) = current($values);
> do {
>       echo include 'template.php';
> } while (list($first_name, $last_name) = next($values));
> ?>

You have misunderstood. You are still putting the template in an
external file. I want it in the main file. I don't want to maintain
two different files.

-- 
"It is always from a minority acting in ways different from what the
 majority would prescribe that the majority in the end learns to do
 better." -- Friedrich Hayek
    Rick Pasotto    [EMAIL PROTECTED]    http://www.niof.net

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to