您的位置 首页 php

PHP文件的读写(配置文件的读写)

第一种:比较简单,但是配置项都在一行显示,不利于观看;

$ file = ‘./Conf/config.php’;//$file = CONF_PATH.’/common.php’;(有时候是这种形式)

$config = array_merge(include $file, array_change_key_case($_POST, CASE_UPPER));

F(‘config’,$config,’./Conf/’);

第二种:有点复杂,不过效果不错,带格式的重写

第一步:读取原文件

$file = ‘./Conf/config.php’;//$file = CONF_PATH.’/common.php’;(有时候是这种形式)

//array_change_key_case($_POST, CASE_UPPER):将”$_POST数据”全部转化为大写

//include $file<==>include ‘./Conf/config.php’;==>//读取config.php文件中的全部数据

第二步:数据重组(相同的内容会被”替换”)

$config = array_merge(include $file, array_change_key_case($_POST, CASE_UPPER));

第三步:重写原文件

$str = “<?phprnreturn ” . var_export($config, true) . “;rn?>”;

file_put_contents($file, $str);

文章来源:智云一二三科技

文章标题:PHP文件的读写(配置文件的读写)

文章地址:https://www.zhihuclub.com/149992.shtml

关于作者: 智云科技

热门文章

网站地图