Question

I've tryed a couple of methods to try and get this working but with no luck!

I've got a page like this (Example):

<?php
$jj = <<<END
?>
<h1>blah blah</h1>
<p> blah blah blah blah blah blah blah <?php include("file.php"); ?> blah blah</p>
<?php
END;
eval('?>'.$jj.'<?php ');
?>

this causes no output what so ever, can not think of a solution!

Was it helpful?

Solution

This will not work because eval only expects PHP code (i.e. not surrounded by <?php ?> tags), so the call to eval() will probably fail with a parse error.

I would suggest using output buffering instead, for example:

<?php
//start output buffering, anything outputted should be stored in a buffer rather than being sent to the browser
ob_start();
?>

<h1>blah blah</h1>
<p> blah blah blah blah blah blah blah <?php include("file.php"); ?> blah blah</p>

<?php
//get contents of buffer and stop buffering
$content = ob_get_clean();
echo $content;
?>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top