Have you found a problem?

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

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.