It is said, that fopen
can use t
mode to convert \n
to \r\n
. So, questions:
1) How should i use t
mode when i need to read and write (r+
)? Should it be r+t
or rt+
or tr+
? Same question for b
, should i write r+b
or how?
2) I've tried all variants on debian linux to convert file, that contains only \n
to \r\n
using magic mode t
(wanna understand how it works). But it does not work. What am I doing wrong? When t
mode works?
Here is my code:
// Write string with \n symbols
$h = fopen('test.file', 'wt');
fwrite($h, "test \ntest \ntest \n"); // I've checked, after file is being created
fclose($h); // \n symbols are not substituted to \r\n
// Open file, that contains rows only with \n symbols
$h = fopen('test.file', 'rt');
$data = fread($h, filesize('test.file'));
fclose($h);
// I want to see what's inside
$data = str_replace("\n", '[n]', $data);
$data = str_replace("\r", '[r]', $data);
// finally i have only \n symbols, \r symbols are not added
var_dump($data);