473,668 Members | 2,371 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=blabla bla

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

BR
Sonnich

Jul 7 '06 #1
3 1276
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=blabla bla

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_repl ace("'setting1\ =.*'", "setting1=blabl abla", $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=blabla bla

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=blabla bla
You may find parse_ini_file( ) useful:

array parse_ini_file ( string filename [, bool process_section s] )

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_section s parameter to TRUE, you get a multidimensiona l array, with
the section names and settings included. The default for process_section s
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
2258
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 getConfig(self,value=None): config = ConfigParser.ConfigParser() config.readfp(open('config.inf')) return config.defaults()
1
1156
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
1119
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
1705
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 denied exception. What could be causing this exception and what should i be looking at to fix the problem. Many Thanks Stuart
8
2064
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 monitor - each field (such as IP, hostname, etc.) is delimited by !!. Now, I want to be able to edit host information from within the GUI - what would be the best way to go about this? Basically I just need to either edit the original host line, or...
5
15061
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 simply persist any changes i made, but it doesn't happen. e.g. selected.ParentNode.ChildNodes.Remove(selected); throws a NotSupportedException "Collection is read-only"
1
1332
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 produces the below error while editing second time. Notice: XML Error:8: undefined entity in /home/thosu/domains/vietgoal.com/public_html/smartway/lib/xml_util.lib on line 370. this is the function present in that line function error() { ...
5
7592
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 form of a key - values) Now when I have to change the available connection or have to add a new one then I have to go to web.config and edit that one. Now the new requirement is to update web.config from an admin module which resides in...
0
756
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 Edit Configuration option which is available in the IIS Properties window (IIS à Site Properties à ASP.NET tab à Edit Configuration Button). Can anybody please tell me how to do it? Thanks in Advance.
0
1097
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 Configuration.Save(...) method, the result file is completely disrupted, and haven’t the same structure. Please I'm really need help!!!
0
8462
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8893
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
7401
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6209
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5681
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4205
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4380
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2792
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 we have to send another system
2
2026
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.