修改config.php配置

$data=array(
"name"=>"222222",
"tel"=>159131,
"address"=>"广州市天河区",
"config['title']"=>"你好中",
);
if(update_config('config.php',$data)){
echo"ok";
}

     function update_config($file, $data,$type="string"){
	 if(!file_exists($file)){
	 return false;
	 }
	 if(!is_array($data)){
	 return false;
	 }
     $str=file_get_contents($file);
	 $str2=$str;
	
    
	 foreach($data as $key=>$val){
	  $pattern='/'.$key.'=(.*?);/i';
	  if(is_int($val)){
        $str2=preg_replace($pattern,$key.'='.$val.';',$str2);
       }else{
	  $str2=preg_replace($pattern,$key.'="'.$val.'";',$str2);
	   }
	 }
	 file_put_contents($file,$str2);
	 return true;
 }

  config.php

<?php
	$name="222222";//kkkk
    $tel=159131;
    $phone=4561321;
    $address="广州市天河区";
?>

  

原文地址:https://www.cnblogs.com/vania/p/4447972.html