PHP寫入txt檔案時的換行問題

2021-09-19 08:40:45 字數 712 閱讀 7421

file_put_contents()函式寫入txt檔案時需要換行。剛開始想到\n

file_put_contents

('./text.txt'

,$out_trade_no,)

;file_put_contents

('./text.txt'

,'\n'

.'---------'

.$amount,)

;

發現會直接輸出,

60459\n---------372
後來改為\r\n發現還是不行。

後來想到可能是因為單引號不解析的問題,改為雙引後就可以正常換行了。

file_put_contents

('./text.txt'

,$out_trade_no,)

;file_put_contents

('./text.txt'

,"\r\n"

.'---------'

.$amount,)

;

37256101

---------157

注:

PHP寫入txt檔案

myfiletoread fopen txt readme.txt r or die unable to open file myfileread fread myfiletoread,20 myfiletowrite fopen txt writeme.txt a or die unable to...

php,linux寫入檔案時怎麼實現換行

錯誤語句 file put contents home web upload faxfailelog.txt v.comm getnow n failestr,lock ex 結果 255 2009 04 09 14 10 13 n255 2009 04 09 14 08 31 r n255 200...

php讀取TXT檔案(帶換行 縮排)

file 與file get contents 一樣,都是讀取某檔案的內容。file get contents 輸出的是整個檔案 不能讀取txt裡的首行縮排和換行符 file 函式把整個檔案讀入乙個陣列中。與 file get contents 類似,不同的是 file 將檔案作為乙個陣列返回。陣列...