Loading a File into Variable - How??

From: Date: Thu, 18 Jul 2002 20:08:20 +0000
Subject: Loading a File into Variable - How??
Groups: php.general 
Request: Send a blank email to php-general+get-108333@lists.php.net to get a copy of this message
I thought this would be fairly easy, but, I can't figure out how to load the contents of a file into a variable so I can output it later. The file to be loaded is in my include_path on the server and does contain some HTML. file_get_contents() is exactly what I need, but, it only works on a CVS version of PHP, whatever that is. I also tried the following function: function file_get_contents($filename) { $fd = fopen ($filename, "r", 1); $contents = fread($fd, filesize($filename)); fclose($fd); return $contents; } But it returns nothing. If I use readfile() the file contents is displayed, but, what I really want to do is store it in a string variable, not output it directly. How can I do this? Thanks, Monty

« previous php.general (#108333) next »