php将数组或字符串写入文件
$fp = fopen("./a.txt", "a+b");
fwrite($fp, var_export($content, true));
fclose($fp);
$fp = fopen("./a.txt", "a+b");
fwrite($fp, print_r($content, true));
fclose($fp);
/*写文件*/
public function dingding_logpro($log_type,$arg)
{
$log = vsprintf("%s", print_r($arg, true));
$log = "执行日期:"."
". date("[Y/m/d H:i:s]") ."---". $log . PHP_EOL;
$log_path = $_SERVER["DOCUMENT_ROOT"]. "/dingding_log/" . $log_type .date("Y-m-d").".txt";
$fp = file_put_contents( $log_path,$log, FILE_APPEND);
return true;
}
public function ding_log($log_type,$data){
$log_file = $_SERVER["DOCUMENT_ROOT"]. "/dingding_log/".$log_type.date("Y-m-d").".txt";
$content =var_export($data,TRUE);
$content .= "
";
file_put_contents($log_file,$content, FILE_APPEND);
}
public function dingding_log($pay_type,$content){
if (is_array($content)) {
$content = json_encode($content);
}
$filename =$_SERVER["DOCUMENT_ROOT"]. "/dingding_log/".$pay_type.date("Y-m-d").".txt";
$Ts=fopen($filename,"a+");
fputs($Ts,"执行日期:"."
".date("Y-m-d H:i:s",time()). " " . "
" .$content."
");
fclose($Ts);
}
//将数组保存在文件中
function export_to_file($file, $variable) {
$fopen = fopen($file, "wb");
if (!$fopen) {
return false;
}
fwrite($fopen, "<?php
return ".var_export($variable, true).";
?>");
fclose($fopen);
return true;
}
//将字符串写入文件
function put_to_file($file, $content) {
$fopen = fopen($file, "wb");
if (!$fopen) {
return false;
}
fwrite($fopen, $content);
fclose($fopen);
return true;
}
TP5
use thinkLog;
Log::write("测试日志信息,这是警告级别,并且实时写入","notice");
声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。
- 上一篇: C/C++上二维数组的两种动态分配内存方法
- 下一篇: mysql 将null转代为0