fopen () function R r+ What's the difference?

Source: Internet
Author: User
Tags readfile
fopen (), followed by the argument,
For example: R
r+
A read-only mode, a read-write mode, exactly what is the difference Ah, why create a back this mode?
Can you pass an example to let me know?


Reply to discussion (solution)

R, can only read fread, cannot write fwrite
R+, both can, and overwrite write

$FN = ' abc.txt '; The file name to be manipulated File_put_contents ($FN, ' 12345 '); Write test Data ReadFile ($FN); Look, the content is 12345//r read-only mode $fp = fopen ($FN, ' R '); $c = Fgetc ($FP); echo $c; Echo fputs ($fp, ' a '); 0 No characters are written to fclose ($FP); ReadFile ($FN); Look, the content of 12345 does not change//r+ read-write mode $fp = fopen ($fn, ' r+ '); $c = Fgetc ($FP); echo $c; Echo fputs ($fp, ' a '); 1 Write 1 characters fclose ($FP); ReadFile ($FN); Look again, the content is 1a345

R can only read the content inside, no permission to write in the file
R+ can write it inside.

  • Related Article

    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.