I couldn’t get PHP to accept an HTML file include as the definition of a variable without throwing my templated page into disarray.  An answer came from the venerable desilva then checked with the php folk; use output  buffering (see example six in that last link):

<?php
$string = get_include_contents('somefile.php');

function get_include_contents($filename) {
 if (is_file($filename)) {
 ob_start();
 include $filename;
 $contents = ob_get_contents();
 ob_end_clean();
 return $contents;
 }
 return false;
}

?>

Also worth a look: file_get_contents

Why? Because Coda, my favourite Macintosh text editor+,  doesn’t do syntax highlighting of HTML for a PHP string. The site I’ve just finished for a high-end luxury villa in Marbella I had a big block of HTML to include (and work on) for the images page…

Last Updated on