PHP implements code for writing LOG logs

不言
Release: 2023-04-03 14:34:01
Original
9913 people have browsed it

This article introduces to you the code for writing LOG logs in PHP. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

public function write_log(){
//设置目录时间
$years = date('Y-m');
//设置路径目录信息
$url  = './public/log/texlog/'.$years.'/'.$years.'_request_log.txt';
//取出目录路径中目录(不包括后面的文件)
$dir_name = dirname($url);
//如果目录不存在就创建
if(!file_exists($dir_name)) {
//iconv防止中文乱码
$res = mkdir(iconv("UTF-8","GBK",$dir_name),0777,true);
}
//$fp = fopen($url,"a");//打开文件资源通道 不存在则自动创建
fwrite($fp,var_export($data,true)."\r\n");//写入文件 
fclose($fp);//关闭资源通道
}
Copy after login

Recommended related articles:

Naming rules for php variables and usage of php variables (with code)

php Get video length And the method of php.ini configuration

The above is the detailed content of PHP implements code for writing LOG logs. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!