Pergunta

I got a problem when I decided to make a system to change a configuration of my web site. I tried to open a file and rewrite a value of param in my conf.ini

conf.ini example:

[order]
show_suspended_orders=0

I want to change the value of "show_suspended_orders" to 1

Here is my code:

$value = 1;
$file = fopen("./conf.ini","w");
preg_replace("/show_suspended_orders=\d+$/","show_suspended_orders=".$value,$file,1);
fclose($file);

The problem is that function preg_replace deletes all the file content. Any idea? Thanks for your help.

Foi útil?

Solução

$value = 1;
$file = file_get_contents("./conf.ini");
$file = preg_replace("/show_suspended_orders=\d+$/","show_suspended_orders=".$value, $file, 1);
file_put_contents("./conf.ini", $file);
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top