Home Backend Development PHP Tutorial PHP 文件操作类(创建文件并写入) 生成日记

PHP 文件操作类(创建文件并写入) 生成日记

Jun 13, 2016 am 11:58 AM
content log mode quot this

PHP 文件操作类(创建文件并写入) 生成日志

<?php /** * 文件操作(生成日志)支持多条插入 * (如果插入多条语句并换行  用&#39;,&#39;逗号分开) * */class log {	public $path 	= &#39;./info.txt&#39;;		//默认值文件	public $mode 	= &#39;a&#39;;				//默认追加写	public $content = &#39;默认值:空&#39;;			//默认内容是 空			public function addlog($path = null, $mode = null, $content = null) {				//判断写入的文件名是否为空		if (! empty ( $path )) {			$this->path = $path;		}				//判断操作方式 a追加写		if (! empty ( $mode )) {			$this->mode = $mode;		}				//判断写入的内容		if (! empty ( $content )) {			$this->content = $content;		}				$handle = fopen ( $this->path, $this->mode );				//拆分换行		$string = explode ( ",", $this->content );		foreach ( $string as $v ) {			fwrite ( $handle, $v . "\r\n" );		}		fclose ( $handle );	}}//使用$log = new log ();// $log->addlog ();	//不传值 走默认值// $log->addlog ( "./log", "a", " 内容1:$content1  内容2: $content2  内容3: $content3 " ); //传多个内容// $log->addlog ( "./log", "a", "123,123,123" ); //一次插入并换行
Copy after login

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Use the math.Log2 function to calculate the base 2 logarithm of a specified number Use the math.Log2 function to calculate the base 2 logarithm of a specified number Jul 24, 2023 pm 12:14 PM

Use the math.Log2 function to calculate the base 2 logarithm of a specified number. In mathematics, the logarithm is an important concept that describes the exponential relationship of one number to another number (the so-called base). Among them, the base 2 logarithm is particularly common and is frequently used in the fields of computer science and information technology. In the Python programming language, we can calculate the base 2 logarithm of a number using the log2 function from the math library. Here is a simple code example: importmathdef

php提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决 php提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决 Jun 13, 2016 am 10:23 AM

php提交表单通过后,弹出的对话框怎样在当前页弹出php提交表单通过后,弹出的对话框怎样在当前页弹出而不是在空白页弹出?想实现这样的效果:而不是空白页弹出:------解决方案--------------------如果你的验证用PHP在后端,那么就用Ajax;仅供参考:HTML code

An article that understands this point and catches up with 70% of front-end people An article that understands this point and catches up with 70% of front-end people Sep 06, 2022 pm 05:03 PM

A colleague got stuck due to a bug pointed by this. Vue2’s this pointing problem caused an arrow function to be used, resulting in the inability to get the corresponding props. He didn't know it when I introduced it to him, and then I deliberately looked at the front-end communication group. So far, at least 70% of front-end programmers still don't understand it. Today I will share with you this link. If everything is wrong If you haven’t learned it yet, please give me a big mouth.

Let's talk about why Vue2 can access properties in various options through this Let's talk about why Vue2 can access properties in various options through this Dec 08, 2022 pm 08:22 PM

This article will help you interpret the vue source code and introduce why you can use this to access properties in various options in Vue2. I hope it will be helpful to everyone!

Use the math.Log10 function to calculate the base 10 logarithm of a specified number Use the math.Log10 function to calculate the base 10 logarithm of a specified number Jul 25, 2023 pm 06:33 PM

Use the math.Log10 function to calculate the base 10 logarithm of a specified number. Logarithms are a common concept in mathematics and computer science. We often use logarithms to describe the size or proportion of numbers. In computer programming, the commonly used logarithmic function is the logarithmic function with base 10. In the Python language, you can use the log10 function in the math library to calculate the base 10 logarithm of a specified number. Below we will demonstrate the use of this function through a simple code example. First, we need

Clever way to use this keyword in jQuery Clever way to use this keyword in jQuery Feb 25, 2024 pm 04:09 PM

Flexible use of this keyword in jQuery In jQuery, the this keyword is a very important and flexible concept. It is used to refer to the DOM element currently being manipulated. By rationally using this keyword, we can easily operate elements on the page and achieve various interactive effects and functions. This article will combine specific code examples to introduce the flexible use of this keyword in jQuery. Simple this example First, let's look at a simple this example. Suppose we have a

What is this? An in-depth analysis of this in JavaScript What is this? An in-depth analysis of this in JavaScript Aug 04, 2022 pm 05:02 PM

What is this? The following article will introduce you to this in JavaScript, and talk about the differences between this in different calling methods of functions. I hope it will be helpful to you!

Use the log.Println function in golang to print log information Use the log.Println function in golang to print log information Nov 18, 2023 pm 12:14 PM

Title: Use the log.Println function in Golang to print log information. Logs are very important in software development. They can help us track various information during program running, such as errors, warnings, debugging information, etc. In Golang, there is a built-in log package, which provides many functions to handle log output. One of the commonly used functions is log.Println, which prints log information to standard output. Below is a simple example code showing how to use log.Print

See all articles