我想要echo輸出並追加到使用php的現有文件。但我得到錯誤。如果我從腳本中刪除「>> master_yml.html」,則屏幕很好。請指教。謝謝如何echo輸出並使用PHP追加到另一個文件
<?php
$filename = './workspace/vars1.txt';
$contents = file($filename);
foreach($contents as $line) {
echo "<TR><TD>$line:</TD><TD> <input type=\"text\"name=\"$line\"size=\"30\" value= $line ></TD> </TR> " >> master_yml.html ;
}
?>
這不是'bash'。你沒有輸出重定向('>>')。相反,你需要使用['file_put_contents'](https://secure.php.net/manual/en/function.file-put-contents.php)或者[fopen'和'fwrite'的組合] ](https://secure.php.net/manual/en/function.fwrite.php)。 – Bytewave
你能舉一個例子嗎? thx – Sean
只是......'echo'字符串,然後'fwrite'相同的字符串文件?我提供了文檔鏈接。 – Bytewave