What is the difference between fopen () function rr +?

Source: Internet
Author: User
What is the difference between fopen () function rr +? Fopen (), the following parameter,
For example, r
R +
What is the difference between a read-only mode and a read/write mode? why do we need to create a later mode?
Can I see through an instance?


Reply to discussion (solution)

R. only fread can be read, and fwrite cannot be written.
R +, both of which can overwrite data

$ Fn = 'abc.txt '; // file name to be operated: file_put_contents ($ fn, '000000'); // write the test data to readfile ($ fn); // take a look, the content is 12345 // r read-only mode $ fp = fopen ($ fn, 'r'); $ c = fgetc ($ fp); echo $ c; echo fputs ($ fp, 'A'); // 0 No character is written into fclose ($ fp); readfile ($ fn); // take a look, the content is 12345 and the read/write mode is not changed. // r + $ fp = fopen ($ fn, 'R + '); $ c = fgetc ($ fp); echo $ c; echo fputs ($ fp, 'A'); // 1 write 1 character fclose ($ fp); readfile ($ fn); // check again, the content is 1a345

R can only read the content, but has no permission to write to the file.
R + can be written inside

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.