php如何修改配置文件
Config.php代码如下:
<?php<br /><br />return array(<br /> 'version' => '20120823',<br /> 'secretKey' => '92fe5927095eaac53cd1aa3408da8135',<br /> 'areaname' => 'China',<br />);<br />
function setConfig($fileName, $value) {<br /> ob_start();<br /> $a = @include($fileName);<br /> ob_end_clean();<br /> if(! is_array($a)) trigger_error("Invalid data file", E_USER_ERROR);<br /> $a['areaname'] = $value;<br /> file_put_contents($fileName, '<?php return ' . var_export($a, 1) . ';');<br />}<br /><br />setConfig('config.php', 'aaa');
function setConfig($key, $value, $fileName='config.php') {<br /> ob_start();<br /> $a = @include($fileName);<br /> ob_end_clean();<br /> if(! is_array($a)) trigger_error("Invalid data file", E_USER_ERROR);<br /> $a[$key] = $value;<br /> file_put_contents($fileName, '<?php return ' . var_export($a, 1) . ';');<br />}<br /><br />setConfig('areaname', 'bbb');