Why does php display in html after execution?

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.