Page 1 of 1

fgets: php code in a text file

Posted: Sat Apr 22, 2006 2:44 pm
by vauneen
hi all,
i'm reading a text file into a php page in a content management system using fgets, but i want people to be able to use html and php code in the text file.
at the moment the php variable are not enterpretted at all.

heres my code:

Code: Select all

<?php		
$handle = @fopen("contentfiles/forgotpw_thanks.txt", "r");
if ($handle) {
while (!feof($handle)) {
     $buffer = fgets($handle, 4096);
     echo $buffer . "<br>";
}
 fclose($handle);					
}
?>
but if i view the source of the page i see the php code from the text file in the client side source.:

Code: Select all

<br>An email has been sent to <b><?php echo $email; ?></b>.
i'm probably missing something really elementary,
any help appreciated.
vauneen

Posted: Sat Apr 22, 2006 3:14 pm
by timvw
That is because you are "reading" not evaluating the file contents...

Anyway, http://www.php.net/include and http://www.php.net/require are what you need (or their *_once friends).

thank timvw

Posted: Sat Apr 22, 2006 3:25 pm
by vauneen
thanks for the help, and for the prompt response.
vauneen