tags:

views:

191

answers:

1

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!

+2  A: 

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;
?>
Tom Haigh
the content needs to be put into a string... is there anyway around doing that?
You can put it inside a heredoc, but it won't get parsed. However, he uses eval afterwards...
Ignas R
@johnnnnnnnnnnnnnnny : $content will contain the evaluated string returned from the output buffer.
Simon Scarfe
Cheers, works perfect!
updated my answer, i answered too quickly and somewhat misunderstood
Tom Haigh