note 30767 added to function.parse-ini-file
| From: | jsheets at shadonet dot com | Date: | Thu, 27 Mar 2003 21:05:24 +0000 |
| Subject: | note 30767 added to function.parse-ini-file | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-45920@lists.php.net to get a copy of this message | ||
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;
}
--
http://www.php.net/manual/en/function.parse-ini-file.php
http://master.php.net/manage/user-notes.php?action=edit+30767
http://master.php.net/manage/user-notes.php?action=delete+30767
http://master.php.net/manage/user-notes.php?action=reject+30767