http://php.net
parse-ini-file有提到類似資料
檔案名稱:listconfig.ini
讀取現有的數據 做成表格form然後發送給ini_update.php上傳
*也可改成ajax方式傳給ini_update.php
index.php
<html>
<body>
<?php
//parse the ini file using default parse_ini_file() PHP function
$parsed_ini = parse_ini_file("listconfig.ini", true);
//after the form submit
?>
<form action="ini_update.php" method="post">
<?php
foreach($parsed_ini as $section=>$values){
echo "<h3>$section</h3>";
//keep the section as hidden text so we can update once the form submitted
echo "<input type='hidden' value='$section' name='$section' />";
//print all other values as input fields, so can edit.
//note the name='' attribute it has both section and key
foreach($values as $key=>$value){
echo "<p>".$key.": <input type='text' name='{$section}[$key]' value='$value' />"."</p>";
}
echo "<br>";
}
?>
<input type="submit" value="Update INI" />
</form>
</body>
</html>
ini_update.php
<?php
if($_POST){
$data = $_POST;
//update ini file, call function
echo update_ini_file($data, "listconfig.ini");
}
//this is the function going to update your ini file
function update_ini_file($data, $filepath) {
$content = "";
//parse the ini file to get the sections
//parse the ini file using default parse_ini_file() PHP function
//$parsed_ini = parse_ini_file("listconfig1.ini", true);
foreach($data as $section=>$values){
//append the section
$content .= "[".$section."]\n";
//append the values
foreach($values as $key=>$value){
$content .= $key."=".$value."\n";
}
}
//write it into file
if (!$handle = fopen("listconfig.ini", 'w')) {
return false;
}
$success = fwrite($handle, $content);
fclose($handle);
return "寫入數據:" . $success;
}
?>