getConfigPath() . $file.".php"; //var_dump( $fileurl); $string = file_get_contents($fileurl); //加载配置文件 foreach ($data as $key => $value) { $pats = '/\'' . $key . '\'(.*?)\',/'; $reps = "'". $key. "'". " => " . "'".$value ."',"; $string = preg_replace($pats, $reps, $string); // 正则查找然后替换 } file_put_contents($fileurl, $string); // 写入配置文件 return true; }else{ return false; } } }