Alternative for ob_get_contents() for mixed PHP/HTML file

711 views Asked by At

I'm trying to parse a mixed HTML/PHP file (viewfile.php) to output it into a html email using the following code:

<?php  
  //define variables and objects to be used in the view
   ...
  ob_start();
  include 'viewfile.php';
  $email_content=ob_get_contents();
  ob_end_clean();
  send_email($email_content);
?>

The viewfile.php to be included looks somehow like this:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en-US">
<head>
<meta charset="UTF-8">
</head>
<body>
    <p>Dear <?= $name ?>,</p>

    <p>You've purchased the following items:</p>
    <?php foreach ($items as $i){?>
    <p><?= $i['name'] ?><br/>
    <?php if (isset($i['item_options'])) foreach ($i['item_options'] as $io) {?>
        <?= $functions->option_name($io['option']).': '.$functions->option_value($io['value']) ?><br/>
    <?php }
    }?></p>
    <p>Best wishes</p>
</body>
</html>

Unfortunately, my webhost doesn't have output_buffering. So, the functions ob_start(); ob_get_contents(); and ob_end_clean(); don't work.

Is there any other way to read file into a variable and parse all the PHP in there. I'm using PHP 5.4.

Thank you very much for your help.

0

There are 0 answers