In php, fread and fgetc obtain the object content in bytes or characters. Why cannot fgetc read the characters?

Source: Internet
Author: User
Hello, I have a question about php file processing. I wrote the upload code to experience fread(development and fgetc(development, the content of the file test.txt is the thisisatestfile.txt file encoded in UTF-8 format {code ...} the above code can obtain the first character t, such... hello, I have a question about php file processing.

I wrote the upload code to experience fread(upload and fgetc(upload, the content in the test.txt file is this is a test file. txt file encoded in UTF-8 format


  

The above code can get the first character t. If fread's second parameter is smaller than 4, nothing can be read!

So the fgetc () below is also blank content.


  

Content not retrieved

My computer is a windows system

How should we understand the second parameter of fread () and a character in fgetc?

Is it because of the file encoding format?

How Should php handle the file encoding format?

Thank you!

Reply content:

Hello, I have a question about php file processing.

I wrote the upload code to experience fread(upload and fgetc(upload, the content in the test.txt file is this is a test file. txt file encoded in UTF-8 format


  

The above code can get the first character t. If fread's second parameter is smaller than 4, nothing can be read!

So the fgetc () below is also blank content.


  

Content not retrieved

My computer is a windows system

How should we understand the second parameter of fread () and a character in fgetc?

Is it because of the file encoding format?

How Should php handle the file encoding format?

Thank you!

I have tried both methods, and I have no problem with the test. My mac. Therefore, the relationship between system file encoding should be slightly determined at the beginning.
In addition, there is a warning in fread's official documentation:
Warning: 'B' must be added to the mode parameter of the fopen () function when a file is opened on a system (such as Windows) that distinguishes binary files from text files '.

At the same time, the fgetc official document prompts:
Note: this function can be safely used for binary objects.

Solution: a prompt is displayed in the document.

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.