您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

php如何修改配置文件

2025/11/5 5:50:54发布14次查看
config.php代码如下:
'20120823', 'secretkey' => '92fe5927095eaac53cd1aa3408da8135', 'areaname' => 'china',);
现在想写个common.php定义setconfig($filename, $value)方法,去修改areaname的值。其中$filename为config.php文件名称, $value为更换的值,不知道具体怎么写??
回复讨论(解决方案) file_get_contents()
file_put_contents()
function setconfig($filename, $value) { ob_start(); $a = @include($filename); ob_end_clean(); if(! is_array($a)) trigger_error(invalid data file, e_user_error); $a['areaname'] = $value; file_put_contents($filename, ' 但是由于你的方案的限制,这个函数有着不通用的毛病
比如要想修改 secretkey 就不可以了
建议改写做 function setconfig($key, $value, $filename='config.php') { ob_start(); $a = @include($filename); ob_end_clean(); if(! is_array($a)) trigger_error(invalid data file, e_user_error); $a[$key] = $value; file_put_contents($filename, ' 楼上正解,好的开发者一定在通用性上有想法
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product