Hello everyone, there is a question about PHP processing files, ask you.
I wrote a piece of code to experience Fread () and fgetc (), and the contents of the file Test.txt are this is a test file. TXT file encoded as Utf-8 format
The above code can get the first character T, if the second parameter of Fread is less than 4 then nothing is read!
So the following fgetc () is also blank content.
Do not get the content
My computer is a Windows system
How do you understand the second argument of Fread () and a character in fgetc?
Is the reason for the file encoding format?
How should PHP handle file encoding format?
Thank you!
Reply content:
Hello everyone, there is a question about PHP processing files, ask you.
I wrote a piece of code to experience Fread () and fgetc (), and the contents of the file Test.txt are this is a test file. TXT file encoded as Utf-8 format
The above code can get the first character T, if the second parameter of Fread is less than 4 then nothing is read!
So the following fgetc () is also blank content.
Do not get the content
My computer is a Windows system
How do you understand the second argument of Fread () and a character in fgetc?
Is the reason for the file encoding format?
How should PHP handle file encoding format?
Thank you!
I have tried both ways, and I have no problem with the test. I use the Mac. Therefore, the initial judgment should be the system file encoding relationship.
In addition, there are warnings in the official documents of Fread:
Warning:在区分二进制文件和文本文件的系统上(如 Windows)打开文件时,fopen() 函数的 mode 参数要加上 'b'。
At the same time, Fgetc's official document has such a hint:
Note: 此函数可安全用于二进制对象。
Workaround, there is a hint in the document.