Why does fgets read the same lines over and over in wrong order?
I have been using fgets
to read a list of (20,000) words in a file. It was working fine yesterday, but somehow now it reads the text file, which is simply a list - out of order, reads some of the same sections over multiple times. It's one word per line. A simple problem, but enough to stop your workflow in its tracks.
$fh = fopen('newsymbols.txt','r') or die($php_errormsg);
while (! feof($fh)) {
if ($s = fgets($fh,1024)) {
Curious if anyone encountered this strangeness from fgets
. I am using this instead of 开发者_JS百科file_get_contents
because this particular script used DOM objects
which eat memory in foreach
loops.
Well you are not iterating through the lines because your while condition have to be setted with fgets
$fh = fopen('newsymbols.txt','r') or die($php_errormsg);
while ($s = fgets($fh,1024)) {
if ( feof($fh)) {
精彩评论