Jump to content

Replaceing a value within an external settings text file.


chrisfane

Recommended Posts

im in the process of creating a method to allow the user to change the config file currently in use.  i have created an html form with a dropdown menu, which passes the filename of the new config file forward to the action page.

 

i have the following in a text file called settings.conf

 

<?php

$confname="config1.conf";

$sqlhost="10.165.250.250"; // add the Automation db Server here.
$username="webstats"; //username for Automation db server
$dbpass=""; //password for Automation db server

//variables which shouldnt be modified
$vers="V 1.4"; // version number, dont change this.
?>

 

and im planning to alter the value of $confname, to config2.conf etc.

 

i cna successfully process the text using an str_replace () command, when the contents of the file is sent as a form post, but i would like to cut that intermediate out, and read directly from the file.

 

so im looking to ...

 

read file in ...

 

run contents through str_replace ($confname , $newconf , $text)

 

output new config file to settings.conf  with ammendments made.

 

 

 

ive tried searching through the forum but havent found anything particularly relevant, if anyone could give me some advice, it would be most appreciated.

Youv'e allready outlined the steps required. All you need do is impliment them.

 

Read the file into an array using file, loop through the array and replace what you need, then write the file back again using fwrite.

 

If you get stuck... post some code.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.