fgets: php code in a text file

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
vauneen
Forum Newbie
Posts: 2
Joined: Sat Apr 22, 2006 2:35 pm

fgets: php code in a text file

Post 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
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post 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).
vauneen
Forum Newbie
Posts: 2
Joined: Sat Apr 22, 2006 2:35 pm

thank timvw

Post by vauneen »

thanks for the help, and for the prompt response.
vauneen
Post Reply