

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; }
本文详细介绍了PHP函数functionfile_write的功能实现,包括如何将数组或常量转换为字符串并写入文件,同时提供了代码示例和使用说明。
1079

被折叠的 条评论
为什么被折叠?



