Have you ever found a problem when using the fread function, if the set file pointer points to a character with an ascii code less than 33 (decimal), it cannot be read no matter how long it is read, A string with a length of 0 is obtained. For example, if the file pointer is set to 18 or 22, has fseek ($ file, 18, SEEK_S found a problem?
When the fread function is used, if the set file pointer points to a character with an ascii code less than 33 (decimal), it cannot be read no matter how long it is read, A string with a length of 0 is obtained. For example:
When the file pointer is set to 18 or 22,
Fseek ($ file, 18, SEEK_SET );
$ Buffer = fread ($ file, 4 );
The resulting $ buffer length is 0.
Is there any difference?
------ Solution --------------------
I tried it. everything is normal and I didn't find what you said. The source code is as follows:
$ Filename = "./1.gif ";
$ Handle = fopen ($ filename, "rb + ");
Fseek ($ handle, 12, SEEK_SET );
$ Buffer = fread ($ handle, 4 );
Var_dump ($ buffer );
------ Solution --------------------
Where did you get it wrong?
// Simulate a file
$ S = "2017d6c0600000000000036000000280000001c00000014000000010018000000 ";
$ Fp = tmpfile ();
Fwrite ($ fp, pack ('H * ', $ s ));
// View in hexadecimal format
Fseek ($ fp, 0 );
$ I = 0;
While ($ I <32 ){
Printf ('% 02x', ord (fgetc ($ fp )));
If (++ $ I % 16) = 0) echo PHP_EOL;
}
/*
42 4d 6c 06 00 00 00 00 00 00 36 00 00 00 28 00
00 00 1c 00 00 00 14 00 00 00 01 00 18 00 00 00
*/
// Enter your question
Fseek ($ fp, 18 );
$ T = fread ($ fp, 4 );
Echo strlen ($ t), ':', bin2hex ($ t );
/*
4: 1c000000
*/