我想编写一个脚本,将结果同时输出到 stdout 和文件。下面的代码可以吗?
echo "<pre>";
ob_start();
$file = fopen("plik.txt", "w") or
exit ("Error opening the file");
for ($i = 0; $i < 10; $i++) {
echo "iter#: $i\r\n";
}
$content = ob_get_flush();
echo "</pre>";
fwrite($file, $content) or
exit("Error writting to the file");