file_put_contents 写入文件

    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

 

posted @ 2016-04-18 11:03  萄子  阅读(330)  评论(0编辑  收藏  举报