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)); ?> -- Jim Lucas "Some men are born to greatness, some achieve greatness, and some have greatness thrust upon them." Twelfth Night, Act II, Scene V by William Shakespeare -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php