将php输出保存在文件中
我有:
echo"
";echo"
";print_r($array2);echo"</pre>";echo"<br>";echo"<br><pre>";print_r($array3);echo"</pre>";echo"<br>";echo"<br><pre>";print_r($array4);echo"</pre>";
我需要将所有这些 print_r 打印的内容保存到一个文件中(不要在页面中打印任何内容).
我知道我需要做这样的事情:
$f = fopen("file.txt", "w");fwrite($f, "要写的文本");fclose($f);
但是我不知道怎么把里面的内容放在里面.
感谢一百万
解决方案使用 print_r
中的 true
参数试试这个:
$f = fopen("file.txt", "w");fwrite($f, print_r($array2, true));fwrite($f, print_r($array3, true));fwrite($f, print_r($array4, true));fclose($f);
I have:
echo"<br>";echo"<br><pre>";print_r($array2);echo"</pre>";
echo"<br>";echo"<br><pre>";print_r($array3);echo"</pre>";
echo"<br>";echo"<br><pre>";print_r($array4);echo"</pre>";
I need to save what all of these print_r print into a file (without pronting anything in the page).
I know I need to do something like that:
$f = fopen("file.txt", "w");
fwrite($f, "TEXT TO WRITE");
fclose($f);
But I don't know how to put the contents before in it.
Thansk a million
解决方案Try this out using the true
param in the print_r
:
$f = fopen("file.txt", "w");
fwrite($f, print_r($array2, true));
fwrite($f, print_r($array3, true));
fwrite($f, print_r($array4, true));
fclose($f);
相关文章