php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #66114 Request to add save_ini_file()
Submitted: 2013-11-18 20:09 UTC Modified: 2018-02-28 22:17 UTC
From: garet at approachfoundation dot org Assigned:
Status: Open Package: Filesystem function related
PHP Version: 5.5.6 OS: Any (FreeBSD)
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2013-11-18 20:09 UTC] garet at approachfoundation dot org
Description:
------------
---
From manual page: http://www.php.net/function.parse-ini-file
---

Though this is a simple request, I think being able to load and save ini files of this format will increase application portability in the long run for many people. If there were also a way to somewhat augment the parsing schema, to catch other common *nix .conf files, t'would be pretty nice.

Test script:
---------------
<?php

//Load my own configuration file for the user running this app
$ThisAppnConfig = parse_ini_file('~/.MyApplication');

//Load the global configuration for some package used in this app
$SomeAppConfig = parse_ini_file('/etc/SomeApp/default.conf');

$ThisAppConfig['SomeApp.host']=$SomeAppConfig['host']
$SomeAppConfig['host']=$ThisAppConfig['host'];

//Update the user's settings to be compatible with my app
save_ini_file($SomeAppConfig,'~/.SomePackage');

//Save the old value in case the user needs it
save_ini_file($ThisAppConfig,'~/.ThisPackage');

?>

Expected result:
----------------
After loading and parsing two, standard configuration document, the developer uses values and may or may not transfer them to/from other config files with the same format.

At the end, a configuration file is generated from the associative array supplied. 

The only caveat is that on saving, a diff tool should be employed to align any pre-existing key/values to their same line number. By only appending new data to the end, we preserve any user-provided comments as well.

Would also be nice to have similar nesting detection both ways. I,e providing the following..


Array
(
    [first_section] => Array
        (
            [one] => 1
            [five] => 5
            [animal] => Dodo bird
        )

    [second_section] => Array
        (
            [path] => /usr/local/bin
            [URL] => http://www.example.com/~username
        )
)

Works as expected to append/replace within a section before falling back to file append.

Actual result:
--------------
None, feature request.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-02-28 22:17 UTC] cmb@php.net
-Package: Unknown/Other Function +Package: Filesystem function related
 
PHP Copyright © 2001-2018 The PHP Group
All rights reserved.
Last updated: Mon Oct 22 04:01:26 2018 UTC