I tried:
$test = include \'test.php\';
But that just included the file normally
Solution #1: Make use of include (works like a function): [My best solution]
File index.php:
File included.php:
test HTML
This will output test HTMLFOO BAR
, but
Note: Works like a function, so RETURN passes contents back to variable (
will be lost in the above)
Solution #2: op_buffer():
File index.php:
File included.php:
test HTML
If you use test HTMLob_get_contents()
it will output FOO BAR
TWICE, make sure you use ob_get_clean()
Solution #3: file_get_contents():
File index.php:
File included.php:
$foo = 'FOO';
print $foo.' '.$bar;
This will output FOO BAR
, but Note: Include.php should not have opening and closing tags as you are running it through eval()