#33981 [Opn->Csd]: parse_ini_file and non-alphanumerics

From: Date: Thu, 04 Aug 2005 12:14:24 +0000
Subject: #33981 [Opn->Csd]: parse_ini_file and non-alphanumerics
References: 1  Groups: php.doc 
Request: Send a blank email to phpdoc+get-969369491@lists.php.net to get a copy of this message
ID: 33981 Updated by: vrana@php.net Reported By: mdc at hotmail dot co dot uk -Status: Open +Status: Closed Bug Type: Documentation problem Operating System: WinXP/Win200 PHP Version: 5.0.4 New Comment: This bug has been fixed in the documentation's XML sources. Since the online and downloadable versions of the documentation need some time to get updated, we would like to ask you to be a bit patient. Thank you for the report, and for helping us make our documentation better. "Characters |&~![()" must not be used anywhere in the key and have a special meaning in the value." Previous Comments: ------------------------------------------------------------------------ [2005-08-03 22:47:54] mdc at hotmail dot co dot uk How about two (or more?) switches of some sort for this function which allow the "illegal" characters to be treated as either expressions or text only? I read your reply and agree there should be something in the documentation about this (There was a comment and bug report about this a while back but was said to have been fixed). After reading your reply I did have a flick through some ini files on my PC and quite a few ini files used brackets as part of the key name.... Nearly all the ini files I checked had brackets in the *value*. I havent checked to see if this problem is apparant for the value, but either way, there might be a good call for allowing them to be used. Thanks for the quick reply. ------------------------------------------------------------------------ [2005-08-03 17:35:40] tony2001@php.net That's because &, !, {, }, (, ), and ~ are considered as parts of an expression and can't appear in keynames. It should be documented, probably. ------------------------------------------------------------------------ [2005-08-03 17:14:21] mdc at hotmail dot co dot uk Description: ------------ When using the parse_ini_file function to parse through a specific section of an ini file ("Applications Packages") the parsing stops whenever the following characters are present in the key()[] Example of ini file: -- [Applicantions Packages] Winamp.ini=INSTALLED Macromedia Shockwave Player 10.ini=INSTALLED Windows (test) Media Player 10 Series.ini=INSTALLED Office XP Security Patch KB830346.ini=INSTALLED Acrobat Reader 6.0.ini=INSTALLED The desired entries in the ini file are output'd to screen as expected until the parsing stops at line 3 and the browser shows: "Warning: Error parsing \\server1\file.ini on line 3 in c:\Inetpub\wwwroot\test\results.php on line 85" (Code snippets included in the next section). I've tried writing additional code to copy the contents to a temporary file, and replace the "illegal" characters with blank spaces, but thats quite inefficent as the ini file can be several hundred lines long and I only need to parse the 20 or 30 lines within it. I've read similar posts regarding this problem, but they're said to be fixed. Reproduce code: --------------- Line 85 of the code is: $settings_array = parse_ini_file($inifile, TRUE); Also relevant, looking for the section "Applications Packages" -- $applications = array_filter($applicationsArray['Applications Packages'], "isInstalledApplications"); -- This is the value to be matched to the keys. -- function isInstalledApplications($var) { return($var == 'INSTALLED' ); } -- Output code. $station is part of the ini file name, which makes up $inifile eg, station1.ini. Could be tidier, I know ;-) -- <?php foreach($applications as $key => $value) { $station = str_replace('.ini', '', $key); $key = str_replace('.ini', '', $key); ?> -- Expected result: ---------------- -- The following items are installed on <workstation name here> Winamp Macromedia Shockwave Player 10 Windows (test) Media Player 10 Series Office XP Security Patch KB830346 Acrobat Reader 6.0 -- Actual result: -------------- -- The following items are installed on <workstation name here> "Warning: Error parsing \\server1\file.ini on line 3 in c:\Inetpub\wwwroot\test\results.php on line 85" Winamp Macromedia Shockwave Player 10 -- ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=33981&edit=1

« previous php.doc (#969369491) next »