Edit report at http://bugs.php.net/bug.php?id=25334&edit=1

 ID:                 25334
 User updated by:    php at richardneill dot org
 Reported by:        php at richardneill dot org
 Summary:            edit_ini_file() function would be nice
 Status:             Wont fix
 Type:               Feature/Change Request
 Package:            PHP options/info functions
 Operating System:   Linux (Mandrake 9.1)
 PHP Version:        4.3.1
 Block user comment: N
 Private report:     N

 New Comment:

Yes...but why re-write this so many times? Since this original report, I
think I've implemented such a system at least 4 times in different ways,
and it seems to be a really obvious candidate for a core library. It's
also quite hard to handle the awkward cases, notably preserving
comments.


Previous Comments:
------------------------------------------------------------------------
[2011-01-01 21:05:47] j...@php.net

For something like this you have plenty of functions in PHP to implement
it yourself in PHP code.

------------------------------------------------------------------------
[2003-08-31 19:25:30] php at richardneill dot org

Description:
------------
Here's an idea that I think would be useful for a new function. I'd like
a way to have an editable equivalent of parse_ini_file(). Many Unix
programs have config files that can be edited *both* by hand, or
automatically by the program. It would be nice to be able to do this in
php. 



Eg if the file myfile.dat contains something like this:

----------------------------

//This is a custom config or data file

$foo="bar"; #comment2

$wibble="bibble";  /*comment 3*/

$aaa=3;

----------------------------



Then, I might call the following in my script:



edit_ini_file (myfile.dat, SET $foo="baz", UNSET $wibble, SET $bbb=4)



And as a result, the file would be appropriately changed, without
modifying the comments. In this case it would become:



----------------------------

//This is a custom config/data file

$foo="baz"; #comment2

$wibble=false;  /*comment 3*/

$aaa=3

$bbb=4;

----------------------------





I'd suggest the function should be able to:



1)SET a variable (i.e. change it if it exists, otherwise, set it)

2)UNSET a variable

3)Add a comment (after a particular variable)

4)Change a comment.







If I can be of any assistance, please let me know. I hope you like the
idea. Thanks for PHP - I love it :-)



------------------------------------------------------------------------



-- 
Edit this bug report at http://bugs.php.net/bug.php?id=25334&edit=1

Reply via email to