PHP file Operation class (create file and write) generate log

Source: Internet
Author: User

<?php/** * File operation (generate log) supports multiple inserts * (if multiple statements are inserted and line breaks  with ', ' comma separated) * */class Log {public $path = './info.txt ';//default file public $mode = ' a ';//default Append write public $content = ' default value: null ';//default content is empty public function addlog ($path = null, $mode = NULL, $content = NULL) {//judgment Whether the file name being written is empty if (! empty ($path)) {$this->path = $path;} Determine how to add a write if (! empty ($mode)) {$this->mode = $mode;} Determine what to write if (! empty ($content)) {$this->content = $content;}  $handle = fopen ($this->path, $this->mode);//split newline $string = Explode (",", $this->content); foreach ($string as $v) {fwrite ($handle, $v. "\ r \ n");} Fclose ($handle);}} Use $log = new log ();//$log->addlog ()/////$log->addlog ("./log", "a", "Content 1: $content 1  content 2: $content 2  Content 3: $content 3 "); Pass multiple content//$log->addlog ("./log", "a", "123,123,123"); Insert and wrap at once

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.