PHP implementation logging (file)

Source: Internet
Author: User

PHP implementation Logging (file) phpphp logging

In the project, it is often necessary to record some operational information, or to print some key variables, or to import Excel files and withdraw records. Often encounter, encapsulate a method, have a bad place or supplement please leave a message.

< Code class= "Nohighlight hljs" style= "border:0; border-radius:4px; font-size:90%; Background-color: #D6DBDF; Color: #e6e1dc; Padding-top:0.5em; Padding-right:0.5em; Padding-bottom:0.5em; Padding-left:0.5em; Display:block; Overflow-x: auto; Background: #232323; -webkit-text-size-adjust:none; "    >header (' content-type:text/html; Charset=utf-8 '); #记录文件 $dir file directory, $filename file name, $data storage data, $Separator delimiter function recordsfile ($dir, $filename, $data =array (), $Separator = ",") {if (! $dir | |! $filename | |!        Is_array ($data)) return false;        if (!is_dir ($dir)) mkdir ($dir);        $content = Implode ($Separator, $data); $result = file_put_contents ($dir. '/'. $filename, (Date (' y-m-d h:i:s ', Time ())). ' '. $content. ' \ r \ n ", File_append |        LOCK_EX);    return $result; }

The test is as follows:

    $dir = ‘E:\website\test\upload/user_excel‘;    //$dir = ‘./upload/user_excel‘;//本地测试报错,权限不足,跟系统环境有关;相关解决可谷歌    $filename = date(‘Ymd‘).‘.txt‘;    $data = array(‘sun‘,24,"是鸟是鱼是尘埃!");    $Separator = "=>";    RecordsFile( $dir,$filename,$data,$Separator );

Tian Jian.

PHP implementation logging (file)

Related Article

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.