1
I have a configuration file, and I would like to edit it by means of a php page instead of going manually by his file, follows below the example.
$db['host'] = '127.0.0.1';
$db['port'] = '3306';
$db['user'] = "root";
$db['pass'] = 'root';
$db['db'] = "database";
What did you try and what was the difficulty? You need more details, because if it’s just the generation of a config text, there are some posts on the site that already have examples; on the other hand, if the config has more than just variables, you need to parse it. If it’s a standard model, you can use placeholders, having the original model with something like
$db['host'] = "$HOST$"
and exchanging the keywords for value (and this is also answered on the site). Without giving more details, it is difficult to define which way is best for your case. It would be good [Dit] and describe the scenario a little better by clarifying these issues– Bacco
I tried to use fwrite but it recreates entire file, and my configuration file won’t just be those 5 lines will have more stuff. this example you gave about changing the keyword $db['host'] = "$HOST$" I searched here on the site and did not find. Would have some link of the topic ?
– Brandow Figueira
This is an example (there are others): https://answall.com/a/54289/70 - note that I answered using a . txt as reference, but vc can save with the extension you want. By doing so, you keep the templates with several $STRINGS$ as markup, and exchange for whatever you want.
– Bacco
Basically you read the original text in a string and swap with:
$configuracao = str_replace( '%PALAVRA%', $palavra, $configuracao );
,– Bacco
Other examples: https://answall.com/a/97733/70 and https://answall.com/a/116791/70
– Bacco