Heim > Fragen und Antworten > Hauptteil
Native PHP verwendet die Funktion parse_ini_file()
, um die INI-Konfiguration zu lesen.
Welche Funktion sollte zum Ändern der Konfigurationselemente verwendet werden?
大家讲道理2017-06-28 09:24:40
修改配置没有原生支持,可以自己实现或者使用别人的轮子
我是搬运工
https://packagist.org/package...
<?php
require 'vendor/autoload.php';
use WriteiniFile\WriteiniFile;
$data = [
'fruit' => ['orange' => '100g', 'fraise' => '10g'],
'legume' => ['haricot' => '20g', 'oignon' => '100g'],
'jus' => ['orange' => '1L', 'pomme' => '1,5L', 'pamplemousse' => '0,5L'],
];
// demo create ini file
$a = new WriteiniFile('file.ini');
$a->create($data);
$a->add([
'music' => ['rap' => true, 'rock' => false]
]);
$a->rm([
'jus' => ['pomme' => '1,5L']
]);
$a->update([
'fruit' => ['orange' => '200g'] // 100g to 200g
]);
$a->write();
echo '<pre>'.file_get_contents('file.ini').'</pre>';
/* output file.ini
[fruit]
orange = "200g"
fraise = "10g"
[legume]
haricot = "20g"
oignon = "100g"
[jus]
orange = "1L"
pamplemousse = "0,5L"
[music]
rap = 1
rock = 0
*/
$b = new WriteiniFile('file.ini');
$b->erase();
$b->write();