Why is php displayed in html after execution. this is to read each line of content from a text file and display it in html. I want to display it in real time, but it seems to be displayed only after all the loops are completed, is there any way to display it cyclically once? $ shili & nbsp ;=& nbsp; fopen & nbsp; (why is this php display in html after it is executed?
. This is to read each line of content from a text file and display it in html. I want to display it in real time, but it seems to be displayed only after all the loops are completed, is there any way to display it cyclically once;
$ Shili = fopen ("test.txt", "r"); // open the text
While (! Feof ($ shili) // determines whether the final function of the file has been reached
{
$ Shi = fgets ($ shili, 1024); // read the data.
$ Xx = "! # $ ^ ";
// $ Headret = PostData ($ shi );
$ Headret = "234234 ";
$ Bodaytext = $ xx. $ headret;
If (strpos ($ bodaytext, 'incorrect password')> 0) // determines whether the returned value is null. if it is null, it is not '-'
{
Echo $ shi. ": Incorrect password "."
";
Continue;
}
Else
{
Echo $ shi. ": The password is correct. Jump out of the loop "."
";
// Break;
}
}
Fclose ($ shili );
------ Solution --------------------
While (true ){
$ N = Count (File ($ file ));
IF ($ N! = $ Total ){
$ Total = $ N;
$ HTM = File ($ file );
Echo '', Htmlspecialchars (End ($ HTM )),'';
Ob_flush ();
Flush ();
} Else {
Usleep (1500 );
}
}
------ Solution --------------------
Php is a server. it will be pushed to the client at one time only after all execution is completed.
If you want to achieve one-by-one display, you need to use buffering, but it seems that the server has to configure something to work.
------ Solution --------------------
The server needs to disable gzip and set the buffer to a smaller value.
The browser also has buffer, which cannot be closed, so every time the server outputs, some blank bytes are filled in.
You can achieve real-time output.
------ Solution --------------------
$ Shi = fgets ($ shili, 5 );
This 5 is too small
The data in your example is zzwc, and there is a carriage return line in the file.
5. I read zzwc \ r, but \ n is not read.
The next read of \ n is over (this is the fgets convention)
Because no data is read, only "incorrect password" is output.