函数file_put_contents();详解与实例

来源:互联网 发布:蚌埠学院网络选课 编辑:程序博客网 时间:2024/06/05 11:36
    
        //对unicode码再进行解码,否则写进日志的不是中文        function decodeUnicode($str)        {            return preg_replace_callback('/\\\\u([0-9a-f]{4})/i',            create_function(                '$matches',                'return mb_convert_encoding(pack("H*", $matches[1]), "UTF-8", "UCS-2BE");'            ),            $str);        }        function addlog( $reqsn , $msg ){            $logarray['data'] = date("Y-m-d H:i:s");            $logarray['reqsn'] = $reqsn;            $logarray['msg'] = $msg;             $josnstr = decodeUnicode(json_encode($logarray));                        file_put_contents("./uplogs/payLogs.txt", $josnstr.PHP_EOL, FILE_APPEND);        }


     
原创粉丝点击