PHP动态修改PHP配置文件(通过正则替换)

PHP动态修改PHP配置文件(通过正则替换)

PHP配置文件

<?php
	$kstime = 0;?>123

获取传值并修改配置文件

<?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"));?>1234567891011

猜你喜欢

转载自blog.csdn.net/tt745/article/details/113813201