Bootstrap

php 写ini_php写入ini文件

修改配置没有原生支持,可以自己实现或者使用别人的轮子

我是搬运工

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 '

'.file_get_contents('file.ini').'
';

/* 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();

;