PHP日志文件不写JSON
我有问题。
我的class.log.php
<?php
date_default_timezone_set('Europe/Istanbul');
class Log
{
public function add($uID, $pID, $text)
{
$date = date("d.m.Y") . " " . date("H:i:s");
$data = array("Date" => $date, "UserID" => $uID, "ProductID" => $pID, "Text" => $text);
$folder = "../log/";
$logFileName = $folder . date("d-m-Y") . ".log";
if (!file_exists($folder)) {
mkdir($folder);
}
if (!file_exists($logFileName)) {
file_put_contents($logFileName, "\xEF\xBB\xBF");
}
$ofile = fopen($logFileName, "a");
fwrite($ofile, $data);
fclose($ofile);
}
}
?>
我在页面中使用它的功能。
require_once "class.log.php";
$log = new Log();
$log->add('41','16','Product Added');
为什么我不能在.log文件中以JSON格式打印输出。 我找不到代码中的错误在哪里
I have a problem.
my class.log.php
<?php
date_default_timezone_set('Europe/Istanbul');
class Log
{
public function add($uID, $pID, $text)
{
$date = date("d.m.Y") . " " . date("H:i:s");
$data = array("Date" => $date, "UserID" => $uID, "ProductID" => $pID, "Text" => $text);
$folder = "../log/";
$logFileName = $folder . date("d-m-Y") . ".log";
if (!file_exists($folder)) {
mkdir($folder);
}
if (!file_exists($logFileName)) {
file_put_contents($logFileName, "\xEF\xBB\xBF");
}
$ofile = fopen($logFileName, "a");
fwrite($ofile, $data);
fclose($ofile);
}
}
?>
I use it function like here in pages.
require_once "class.log.php";
$log = new Log();
$log->add('41','16','Product Added');
why can't I print output in json format to my .log file.
I can't find where is the error in the codes
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
写入文件时,您应该将数组转换为字符串
使用此代码
when write to file you should convert array to string
use this code