Imagine we have 2 files, one called 1.php with the following code:
<?php
$hello = "Hello from 1";
?>
and 2.php with the following code:
<?php
function LoadPage( $page )
{
$f = fopen( $page, 'r+' );
$content = fread( $f, filesize($page) );
fclose( $f );
return $content;
}
function GetEvalContent( $content )
{
$var = "";
ob_start();
eval( "?>" . $content . "<?" );
$var = ob_get_contents();
ob_end_clean();
return $var;
}
$hello = "hello from 2";
echo $hello . '<br/>';
$content = LoadPage( '1.php' );
GetEvalContent( $content );
echo $hello;
?>
So what the 2.php does is load the content of 1.php and evaluate the php code inside it. Now what I want to do is during the evaluation of 1.php, variable $hello changes to "hello from 1". However if you execute 2.php you always get:
"hello from 2"
"hello from 2"
instead of getting
"hello from 2"
"hello from 1"
Has anyone encountered this problem before and if so, how would you fix it?
eval( "?>" . $content . "<?" );is not valid syntax.eval.