I have one php page (index.php) with following contents:
<php
include("{$_SERVER['DOCUMENT_ROOT']}/somefunction.php")
echo "hello world";
?>
Now I want to read the contents of index.php via another php-file (test.php) The result I want to get is:
line 1: include("{$_SERVER['DOCUMENT_ROOT']}/somefunction.php")
line 2: echo "hello world";
This is what I already tried, but it won't work:
$phppage="{$_SERVER['DOCUMENT_ROOT']}/index.php";
$handle = fopen($phppage, "r");
if ($handle) {
while (($line = fgets($handle)) !== false) {
// process the line read.
echo $line;
}
fclose($handle);
}
else {
// error opening the file.
echo "An error occured";
}
It just echoes an empty string.
Problem solved :-)