zoukankan      html  css  js  c++  java
  • PHP 文件操作类(创建文件并写入) 生成日志

    <?php
    /**
     * 文件操作(生成日志)支持多条插入
     * (假设插入多条语句并换行  用','逗号分开)
     *
     */
    class log {
    	public $path 	= './info.txt';		//默认值文件
    	public $mode 	= 'a';				//默认追加写
    	public $content = '默认值:空';			//默认内容是 空
    		
    	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 . "
    " );
    		}
    		fclose ( $handle );
    	}
    }
    
    //使用
    
    $log = new log ();
    // $log->addlog ();	//不传值 走默认值
    // $log->addlog ( "./log", "a", " 内容1:$content1  内容2: $content2  内容3: $content3 " ); //传多个内容
    // $log->addlog ( "./log", "a", "123,123,123" ); //一次插入并换行

  • 相关阅读:
    zzuli2470: 迷宫
    zzuli2460: 楼上真的是签到题
    zzuli2460: 楼上真的是签到题
    洛谷P1044 :栈(卡特兰数)
    洛谷P1044 :栈(卡特兰数)
    洛谷P1056:排座椅(贪心)
    代码块地址
    tabBarItem动画
    vim Podfile
    webView进度条
  • 原文地址:https://www.cnblogs.com/mengfanrong/p/5156593.html
Copyright © 2011-2022 走看看