note 30767 deleted from function.parse-ini-file by victor

From: Date: Sat, 19 Jun 2004 15:18:56 +0000
Subject: note 30767 deleted from function.parse-ini-file by victor
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-71355@lists.php.net to get a copy of this message
Note Submitter: jsheets@shadonet.com ---- I've written a function that helps deal with the "special" characters mentioned above, specifically I needed to use & in an .ini file and was not able to do so because & causes a parse error. I wrote a function that replaces .number. with the ascii character that corresponds to number, for example [main] test .38. = .38. is a special character becomes test & = & is a special character, as you can see it replaces both the key and the value in the ini file. An example usage is: $config = fix_config(parse_ini_file('settings.ini', '1)); The code is: function fix_config($array) { foreach ($array as $key => $value) { if (is_array($value)) { $return[$key] = fix_config($value); } else { $newkey = preg_replace_callback('/\.[0-9]+\./', create_function('$array', 'return chr(str_replace(".", "", $array[0]));'), $key); $value = preg_replace_callback('/\.[0-9]+\./', create_function('$array', 'return chr(str_replace(".", "", $array[0]));'), $value); if (!empty($newkey)) { $return[$newkey] = $value; } else { $return[$key] = preg_replace_callback('/\.[0-9]+\./', create_function('$array', 'return chr(str_replace(".", "", $array[0]));'), $key); } } } return $return; }

« previous php.notes (#71355) next »