I'm trying to load a file 'test.php' into a variable.
file test.php:
<?php
print("Hello");
?>
when i try to load the file:
$tmp = file_get_contents('test.php');
i get an empty variable.
Is it possible to get a php content from a file?
load php script from file
Moderator: General Moderators
RPY
I'm familiared with include(), require(),... but this is not what i want, because i don't want a compiled code.
I just want to read a php script from a file. But if i read a php script from a file with standard file handling functions i can only read a non-php content.
Everything between (<?PHP ?>) just disappeare.
I just want to read a php script from a file. But if i read a php script from a file with standard file handling functions i can only read a non-php content.
Everything between (<?PHP ?>) just disappeare.
Success!
After a little search i found a way. Function file_get_contents(file) gave me a desired result.
Example:
temp.php:
$code = file_get_contents("temp1.php");
$src = file_get_contents("temp2.html");
$ret = str_replace('%SECOND%', $code, $src);
$ret = '?>'.$ret;
eval($ret);
temp1.php:
<STRONG>
<?PHP
print("second");
?></STRONG>
temp2.html:
First<BR>
%SECOND%<BR>
Third.<BR>
The result of the script is:
First
Second
Third
thank you!

After a little search i found a way. Function file_get_contents(file) gave me a desired result.
Example:
temp.php:
$code = file_get_contents("temp1.php");
$src = file_get_contents("temp2.html");
$ret = str_replace('%SECOND%', $code, $src);
$ret = '?>'.$ret;
eval($ret);
temp1.php:
<STRONG>
<?PHP
print("second");
?></STRONG>
temp2.html:
First<BR>
%SECOND%<BR>
Third.<BR>
The result of the script is:
First
Second
Third
thank you!
Code: Select all
/*ignore this line, it is simply in place to correct the syntax highlighting on the forums*/?>
First<BR>
<?php include("temp1.php"); ?><BR>
Third.<BR>