首页 > 其他 > 详细

file_put_contents 写入文件

时间:2016-04-18 11:46:19      阅读:108      评论:0      收藏:0      [点我收藏+]
技术分享
    function file_write($file, $string, $type = ‘array‘)  
    {  
        if(is_array($string))  
        {  
            $type = strtolower($type);  
            if($type == ‘array‘)  
            {  
                $string = "<?php\n return ".var_export($string,TRUE).";\n?>";  
            }  
            elseif($type == ‘constant‘)  
            {  
                $data=‘‘;  
                foreach($string as $key => $value) {
                    $data .= "define(‘".strtoupper($key)."‘,‘".addslashes($value)."‘);\n";  
                    $string = "<?php\n".$data."\n?>";  
                }
            }  
        }  
        $filePath = $file;
        $strlen = file_put_contents($filePath, $string, LOCK_EX);
        chmod($filePath, 0777);  
        return $strlen;  
    }  
View Code

 

file_put_contents 写入文件

原文:http://www.cnblogs.com/gengting/p/5403651.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!