you didn't mention file()

that one can be pratical because it returns an array of lines (linefeed 
intact, implode with empty string),
but can be memory consuming for large files, because the entire file is 
in memory
the at the same time.

some times you don't need the entire file (at a time) ..
for example
fread() allows you to read a specific length
fgets() one text line at a time with max length
fgetss() ..and strip HTML..
fgetcsv() or return a line from a .csv as an array..

not really ambiguous,
and I think these functions being flexible enough to handle other 
resource types can hardly be seen as a disadvantage..

bvr.

Erik Price wrote:

> 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
> [EMAIL PROTECTED]
>
>



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to