The code for reading an empty character from a file using fread in PHP is as follows: PHPcode $ fileSizefilesize ($ filePath); $ handlefopen ($ filePath, & quot; rb & quot ;); while (! Feof ($ handle) {var_dump (fread ($ handle, there will always be one more blank character for PHP to read files using fread
The code is as follows:
PHP code
$ FileSize = filesize ($ filePath); $ handle = fopen ($ filePath, "rb"); while (! Feof ($ handle) {var_dump (fread ($ handle, $ fileSize); // An empty character is output once more}
Thank you!
------ Solution --------------------
Fread ($ handle, $ fileSize)
The file contains $ fileSize bytes, and the read is successful. Therefore, the program does not detect the file. Then the second loop will be executed, and the pointer is located at the last bit, and there is no readable, so the system sets the file pointer to the bottom, so feof () returns true. There is almost no difference between the php operating file system and C. Here, we have a very detailed explanation of the feof () of C.
------ Solution --------------------
In fact, I did not mention the idea. for the solution, you can set $ fileSize + 1. or you can read all the file content without repeating fread ($ handle, filesize ($ filename.
------ Solution --------------------
Trim?
------ Solution --------------------
If the file is not large, read all the arrays and remove the last one. If the file is large, you can try another method. However, if you do not find any more files, what will happen. It is not difficult to remove it.
------ Solution --------------------
Because you are on the WINDOWS platform, files are stored in the open text file. a special byte Mark file ends at the end of the file. you can use rb to open the file and read the last special byte.
Open it with r. read it with fgets.