将php输出保存在文件中

Saving php output in a file(将php输出保存在文件中)
本文介绍了将php输出保存在文件中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我有:

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); 

这篇关于将php输出保存在文件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Deadlock exception code for PHP, MySQL PDOException?(PHP、MySQL PDOException 的死锁异常代码?)
PHP PDO MySQL scrollable cursor doesn#39;t work(PHP PDO MySQL 可滚动游标不起作用)
PHP PDO ODBC connection(PHP PDO ODBC 连接)
Using PDO::FETCH_CLASS with Magic Methods(使用 PDO::FETCH_CLASS 和魔术方法)
php pdo get only one value from mysql; value that equals to variable(php pdo 只从 mysql 获取一个值;等于变量的值)
MSSQL PDO could not find driver(MSSQL PDO 找不到驱动程序)