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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.