Home > Backend Development > PHP Tutorial > PHP向txt文件里面写入字符串,换行有关问题

PHP向txt文件里面写入字符串,换行有关问题

WBOY
Release: 2016-06-13 11:56:32
Original
1022 people have browsed it

PHP向txt文件里面写入字符串,换行问题

<br />$DOCUMENTROOT = $_SERVER['DOCUMENT_ROOT'];<br />    $file = fopen("$DOCUMENTROOT/php_02/123.txt","wb");<br />    fwrite($file,"line 1 "."\n"." line 2 n line 3");<br />    fclose($file);<br />
Copy after login

这样没用
但是
<br />$DOCUMENTROOT = $_SERVER['DOCUMENT_ROOT'];<br />    $file = fopen("$DOCUMENTROOT/php_02/123.txt","wb");<br />    fwrite($file,"line 1 "."\r\n"." line 2 n line 3");<br />    fclose($file);<br />
Copy after login

这样就可以了,问问为什么
------解决方案--------------------
是不同的编辑器解析效果不同

在命令行里面分别打开以下两个程序,然后用程序打开生成的文件,就可以看出程序是怎么解析\n的了
notepad
wordpad

Windows下很多编辑器把\r\n当换行,忽略\n

你把Word显示控制字符功能打开,\n显示为向下的箭头,\r\n显示为拐弯的箭头
------解决方案--------------------
window \r\n
linux \n

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template