php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #25334 edit_ini_file() function would be nice
Submitted: 2003-08-31 19:25 UTC Modified: 2011-01-01 21:14 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: php at richardneill dot org Assigned:
Status: Wont fix Package: PHP options/info functions
PHP Version: 4.3.1 OS: Linux (Mandrake 9.1)
Private report: No CVE-ID: None
 [2003-08-31 19:25 UTC] 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 :-)


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-01-01 21:05 UTC] jani@php.net
-Status: Open +Status: Wont fix -Package: Feature/Change Request +Package: PHP options/info functions
 [2011-01-01 21:05 UTC] jani@php.net
For something like this you have plenty of functions in PHP to implement it yourself in PHP code.
 [2011-01-01 21:14 UTC] php at richardneill dot org
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.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 12:01:31 2024 UTC