Questions about PHP using Fread to read files will always be one more empty character
The code is as follows:
PHP Code
$fileSize = FileSize ($filePath), $handle = fopen ($filePath, "RB"), while (!feof ($handle)) { var_dump (fread ($handle), $fileSize)); Will output one more empty character}
For advice, thank you!
------Solution--------------------
Fread ($handle, $fileSize)
The file has exactly $fileSize bytes of content, read smoothly, so the program did not detect the end of the file. Then the second loop is executed, and the pointer is at the last, and there is nothing to read, so the system only sets the file pointer to the bottom, so that feof () returns True. PHP operation file System and C almost no difference, this aspect has about C feof () has a very detailed explanation
------Solution--------------------
In fact, I did not say a point. As for the solution, it can be $fileSize +1. Or you can do it completely without cyclic fread ($handle, FileSize ($filename)); To read all the file contents.
------Solution--------------------
Trim () a bit?
------Solution--------------------
If the file is not large, read it all to the array and remove the last one. If the file is large, another thought of its method, but did not find much of this will affect what ah. Really affect, want to get rid of should also not be difficult.
------Solution--------------------
Because you are the Windows platform, the file is the text to open the stored content, at the end there will be a special byte to identify the end of the file, you can use the RB open nature will be able to read the last special byte.
Open with R, Fgets read it.