473,508 Members | 2,274 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Editing a (config) file

Hi

I have a file with some configation in it... I am wondering how I
correct single values in there.

The most secure is to recreate the file, then rename it.

But is there a way to correct a line in the text file?
setting1=bla -setting1=blablabla

Needless to say, there are things in there I'd like to keep at all
times.

BR
Sonnich

Jul 7 '06 #1
3 1265
Sonnich schrieb:
Hi

I have a file with some configation in it... I am wondering how I
correct single values in there.

The most secure is to recreate the file, then rename it.

But is there a way to correct a line in the text file?
setting1=bla -setting1=blablabla

Needless to say, there are things in there I'd like to keep at all
times.

BR
Sonnich
You could use preg_replace() (have a look at php.net).

For your Example it could be

--snip--
//Read the contents of the file into $file

$file=preg_replace("'setting1\=.*'", "setting1=blablabla", $file);

//Write $file back to the file.
--snap--

Or do I misunderstand your question?
Jul 7 '06 #2
Sonnich wrote:
Hi

I have a file with some configation in it... I am wondering how I
correct single values in there.

The most secure is to recreate the file, then rename it.

But is there a way to correct a line in the text file?
setting1=bla -setting1=blablabla

Needless to say, there are things in there I'd like to keep at all
times.

BR
Sonnich
I would read the file into an associative array, update the value based
on the key, write a new file, rename it to the original. I might also
flock() the original configuration file if the operating system does not
support atomic rename/move.

-david-

Jul 7 '06 #3
*** Sonnich escribió/wrote (7 Jul 2006 01:55:03 -0700):
I have a file with some configation in it... I am wondering how I
correct single values in there.

The most secure is to recreate the file, then rename it.

But is there a way to correct a line in the text file?
setting1=bla -setting1=blablabla
You may find parse_ini_file() useful:

array parse_ini_file ( string filename [, bool process_sections] )

parse_ini_file() loads in the ini file specified in filename, and returns
the settings in it in an associative array. By setting the last
process_sections parameter to TRUE, you get a multidimensional array, with
the section names and settings included. The default for process_sections
is FALSE
--
-+ http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
++ Mi sitio sobre programación web: http://bits.demogracia.com
+- Mi web de humor con rayos UVA: http://www.demogracia.com
--
Jul 8 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2248
by: Mike Zupan | last post by:
I need to edit the value(s) of a config file via a GUI interface. I'm trying to use ConfigParser but set() doesn't seem to write. Here are my reading and writing functions def...
1
1154
by: ABC | last post by:
Web.Config Editing have no intellisense feature on VC# web site project under VS IDE 2005. How can I turn it on?
4
1106
by: ABC | last post by:
Web.Config Editing have no intellisense feature on VC# web site project under VS IDE 2005. How can I turn it on?
4
1700
by: Stuart Ferguson | last post by:
I am attempting to put a screen in a web application that allows editing of AppSettings values in the Web.Config file using the Web Configuration manager class however on he .Save i get an access...
8
2050
by: D | last post by:
Hi, I currently have a Python app with a Tkinter GUI frontend that I use for system administration. Everytime it launches, it reads a text file which contains info about each host I wish to...
5
15035
by: Tim Mackey | last post by:
hi, i have put my web.sitemap in /App_Data so i can edit it programatically via a web admin page, inheriting the modify permissions from the App_Data folder etc. i was hoping the provider would...
1
1328
by: karthickassistanz | last post by:
Hi Friend, I have a language file in the path /public_html/smartway/conf/config/lang/text.register_seeker.php.While editng this file in vietnam language,i can edit it for first time and...
5
7583
by: Spanco | last post by:
My web application is using multiple databases according to user requirement. Means user can choose the database from available database ( Available databases are maintained in web.config file in...
0
749
by: dhanashivam | last post by:
Hi All, I would like to know how to edit the web.config file at installation time. The values for the attributes will be given by the user. I would like to have this editing option like the...
0
1088
by: ibel.groups | last post by:
Hello I treat to build an application that modified the configuration file (.exe.config) of another application. I'm using the class ConfigurationManager but when I save the changes with...
0
7229
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7398
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7061
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7502
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5637
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4716
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3208
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1566
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
428
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.