据说fopen可以使用tmode转换\n为\r\n. 所以,问题:
1)t当我需要读写( )时,我应该如何使用模式r+?应该是r+torrt+还是tr+?同样的问题b,我应该写r+b还是怎么写?
2)我已经尝试了 debian linux 上的所有变体来转换文件,其中只包含\n使用\r\n魔法模式t(想了解它是如何工作的)。但它不起作用。我究竟做错了什么?模式什么时候t起作用?
这是我的代码:
// 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);