RE: [PHP] best way to read a file

From: Date: Fri, 29 Mar 2002 00:10:51 +0000
Subject: RE: [PHP] best way to read a file
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-90614@lists.php.net to get a copy of this message
Actually if you have output buffering active then the easiest hassle free way to read a file into a variable is like this.. <? ob_start(); readfile($url, 10000); $file = ob_get_contents(); ob_end_clean(); echo $file; ?> Pretty cool eh? Hope that helps. -- Kevin Stone Kevin@helpelf.com -----Original Message----- From: Erik Price [mailto:pricee@hhbrown.com] Sent: Thursday, March 28, 2002 5:03 PM To: php-general@lists.php.net Subject: [PHP] best way to read a file This is a really simple question that I've wondered for a while now... what is the best way to read a file? There are so many different functions for reading files that I have no idea which I should use. readfile() returns its values to standard output -- I don't want to use this, since my script needs to load the data in the file into a variable (it's a .xsl file). fgets() looks like it could work if I made an array out of each line read and then imploded them. fread() looks like the 'main' function for reading from files. fpassthru() -- I guess if you're already in the middle of a file it's a good way to finish? There are other functions for reading files, but they are less ambiguous, with purposes like reading from sockets or certain kinds of files. I'm not interested in those -- I just want to know which function I should use to simply read a file and store the file's contents in a variable (for later actions to be performed on/with this variable). Thank you. Erik ---- Erik Price Web Developer Temp Media Lab, H.H. Brown pricee@hhbrown.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php

« previous php.general (#90614) next »