On Saturday 11 January 2003 10:47 pm, Marco Tabini wrote: > You don't specify if you want to read a *particular* line from a file. > If so, I think there really is no way short of scanning the file with > fgets() or by perhaps using some external utility such as grep or sed.
scanning the file with fgets is very slow. using external tools which are specialized for the task of scanning for lines will generally yield much better results. if you're on unix, then a combination of head and tail (or just head or tail, if you just want the first or last line of a file) will generally get you any line. e.g., if you want the 5th line of a file, you can say: cat filename | head -n 5 | tail -n 1 (use popen to start that process running and read its output). on the other hand, if you don't know just which line number it is you want, then some more complicated method (probably involving grep, as suggested by Marco) will generally get you what you need. if what you need is even more complex than this, then you will probably just have to scan the file with fgets although it might still be possible with a combination of unix command line tools such as head, tail, grep, etc). if you're on windows and don't have access to those tools, well, you're on your own. you would probably be able to get better performance by writing the program to get the line in C/C++ or some other compiled language and just popen that from php. tiger -- Gerald Timothy Quimpo tiger*quimpo*org gquimpo*sni-inc.com tiger*sni*ph Public Key: "gpg --keyserver pgp.mit.edu --recv-keys 672F4C78" Veritas liberabit vos. Doveryai no proveryai. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php