我希望能夠寫入文件並始終在該行寫入。寫入文件中的特定行
1 Hello
2 How are you
3 Good
4 I see
5 Banana
6 End
使用功能:
function filewriter($filename, $line, $text,$append) {
}
所以追加=增加而不會覆蓋線路,這是可選的,因爲它會默認爲追加
所以追加:
filewriter ("bob.txt", 2, "Bobishere", true) or filewriter ("bob.txt", 2, "Bobishere")
輸出:
1 Hello
2 Bobishere
3 How are you
4 Good
5 I see
6 Banana
7 End
,但如果他們不追加它看起來像這樣: 的FileWriter( 「bob.txt」,2, 「Bobishere」,假)
輸出:
1 Hello
2 Bobishere
3 Good
4 I see
5 Banana
6 End
我只有設法弄清楚如何覆蓋文件或添加到文檔的末尾。
什麼功能看起來像目前:
function filewriter($filename,$line,$text,$append){
$current = file_get_contents($filename);
if ($append)
$current .= $line;
else
$current = $line;
file_put_contents($file, $current);
}
向我們顯示您的代碼,我們可以查找錯誤。 – Sablefoste
完成!對不起,我只是覺得它沒用:x –
爲什麼所有的標籤?這裏只有php –