我一直在進(jìn)行測(cè)驗(yàn),并且遇到需要將答案保存到文本文件的情況。我想出了一些代碼:<?php $myfile = fopen("myfile.txt", "r+") or die("Unable to open file!"); $txt = "Name:\n"; fwrite($myfile, $txt); $txt = "Student1\n"; fwrite($myfile, $txt); $txt = "Marks:\n"; fwrite($myfile, $txt); $txt = "0\n"; fwrite($myfile, $txt); echo fread($myfile,filesize("myfile.txt")); fclose($myfile);?>但我注意到,這只想寫(xiě)入內(nèi)容已存在的文件,而無(wú)法創(chuàng)建新文件并寫(xiě)入它。有什么辦法可以做到這一點(diǎn)嗎?
1 回答

慕哥9229398
TA貢獻(xiàn)1877條經(jīng)驗(yàn) 獲得超6個(gè)贊
它應(yīng)該w+
代替r+
$myfile = fopen("myfile.txt", "w+")
- 1 回答
- 0 關(guān)注
- 116 瀏覽
添加回答
舉報(bào)
0/150
提交
取消