Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.10.12

Request #6385 Allow colon in ini file key
Submitted: 2006-01-01 07:10 UTC
From: shannah at sfu dot ca Assigned: aashley
Status: Closed Package: Config
PHP Version: Irrelevant OS: All
Roadmaps: (Not assigned)    
Subscription  


 [2006-01-01 07:10 UTC] shannah at sfu dot ca
Description: ------------ Not sure if this is a bug or not, but it is handy to be able to include colons in the keys of ini files eg: [section1] widget:type = "select" widget:label = "My Section" widget:description = "My Description" Currently the iniCommented will not accept the colon character. I have changed my local copy of Config/IniCommented.php to allow this. The diff file is as follows: 72c72 < } elseif (preg_match('/^\s*([a-zA- Z0-9_\-\.\s:]*)\s*=\s*(.*)\s*$/', $line, $match)) { --- > } elseif (preg_match('/^\s*([a-zA- Z0-9_\-\.\s]*)\s*=\s*(.*)\s*$/', $line, $match)) {

Comments

 [2006-01-03 01:14 UTC] aashley at php dot net
How should these field names be handled when converting to other config file formats. For example in XML the : is used to seperate a namespace from the tag name, and unless the name space is specified in the header its not valid. I'm not sure on its allowance in Apache style configs either (tho i suspect its allowed). Finally what is the php parse_ini_file() functions interpretation of this. It is used in IniFile.php and other than supporting comments I'd like to keep the two ini file versions as similar as possible
 [2006-01-03 01:25 UTC] shannah at sfu dot ca
I see your point about XML compatibility. There doesn't seem to be a perfect solution for the cross compatibility - other than user responsibility to name things appropriately if they will be using XML. parse_ini_file() allows colons in key names. This is what I was using prior to switching to PEAR Config. Eg: inifile.ini ---- [section] widget:label="Test Label" widget:description = "Test Description" test.php ---- <? $arr = parse_ini_file("inifile.ini", true); print_r($arr); ?> outputs: Array ( [section] => Array ( [widget:label] => "Test Label", [widget:description] => "Test Description" ) )
 [2006-01-03 01:31 UTC] shannah at sfu dot ca
One possibility for the XML version would be to translate colonized keys into nested XML tags: eg: [section] widget:label = "Test Label" translates to <section> <widget> <label>Test Label</label> </widget> </section>
 [2006-01-03 03:00 UTC] aashley at php dot net
Seeing as php's parse_ini_file() supports : in the keys I've added support for it to IniCommented.php. It is in CVS now and will be available in the next bug fix release. I'm leaving this ticket open for now to deal with the translation to other Config formats.
 [2006-02-14 00:04 UTC] aashley at php dot net
This is out there and fixed. If someone has problems with colons in other formats they can open a new bug.