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

WBOY
Freigeben: 2016-07-13 10:28:44
Original
899 Leute haben es durchsucht

<?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" ); //一次插入并换行
Nach dem Login kopieren

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/780967.htmlTechArticlepath = $path;}//判断操作方式 a追加写if (! empty ( $mode )) {$this->mode = $mode;}//判断写入的内容if (! empty ( $content )) {$this->content = $content;}$handle = fop...
Verwandte Etiketten:
Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!