fopen () function R r+ What's the difference?
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?
------to solve the idea----------------------
R, can only read fread, cannot write fwrite
R+, both can, and overwrite write
------to solve the idea----------------------
$FN = ' abc.txt '; File name to be manipulated
File_put_contents ($FN, ' 12345 '); Writing 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
Fclose ($FP);
ReadFile ($FN); Look, the content is 12345 unchanged.
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
------to solve the idea----------------------
R can only read the content inside, no permission to write in the file
R+ can write it inside.