PHP动态修改PHP配置文件(通过正则替换)
PHP配置文件
<?php
$kstime = 0;
?>
获取传值并修改配置文件
<?php
$kstime = $_REQUEST["kstime"];
if ($kstime <>''){
$info=file_get_contents("../config/config.php");//打开文件
$pattern = '/kstime= (.*?);/';//正则语句
$info = preg_replace($pattern, 'kstime= '.$kstime .';', $info);//正则替换
file_put_contents("../config/config.php",$info);//保存文件
}
echo json_encode(array('code'=>"0",'msg'=>"true"));
?>