php向txt文件里面写入字符串,换行问题
$documentroot = $_server['document_root'];
$file = fopen($documentroot/php_02/123.txt,wb);
fwrite($file,line 1 .\n. line 2 n line 3);
fclose($file);
这样没用
但是
$documentroot = $_server['document_root'];
$file = fopen($documentroot/php_02/123.txt,wb);
fwrite($file,line 1 .\r\n. line 2 n line 3);
fclose($file);
这样就可以了,问问为什么
------解决方案--------------------
是不同的编辑器解析效果不同
在命令行里面分别打开以下两个程序,然后用程序打开生成的文件,就可以看出程序是怎么解析\n的了
notepad
wordpad
windows下很多编辑器把\r\n当换行,忽略\n
你把word显示控制字符功能打开,\n显示为向下的箭头,\r\n显示为拐弯的箭头
------解决方案--------------------
window \r\n
linux \n