如何使用PHP回显输出并附加到另一个文件

时间:2017-02-18 00:03:23

标签: php

我尝试回显输出并使用php附加到现有文件。但是我收到了错误。如果我删除"屏幕上的输出是好的。 >> master_yml.html"从脚本。请指教。感谢

 <?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 ;
  }

  ?>

1 个答案:

答案 0 :(得分:0)

使用combination of fopen() and fwrite()

对于你的例子:

<?php

$filename = './workspace/vars1.txt';
$contents = file($filename);
$file = fopen('master_yml.html', 'a');

foreach ($contents as $line) {
    $str = "<TR><TD>$line:</TD><TD> <input type=\"text\"name=\"$line\"size=\"30\" value= $line ></TD> </TR> ";
    echo $str;
    fwrite($file, $str);
}

fclose($file);
相关问题