note 94192 deleted from function.parse-ini-string by googleguy
| From: | googleguy@php.net | Date: | Thu, 13 Jun 2013 14:28:28 +0000 |
| Subject: | note 94192 deleted from function.parse-ini-string by googleguy | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-195198@lists.php.net to get a copy of this message | ||
Note Submitter: alexandre at nospam dot imaginacom dot com
----
If your server has yet not been updated to PHP 5.2 (like mine), the following function can help you
without having to use temporary paths.
I tried to make it the more similar possible to the PHP's behaviour, including dealing with
errors or exceptions.
<?php
if(!function_exists('parse_ini_string')){
function parse_ini_string($str, $ProcessSections=false){
$lines = explode("\n", $str);
$return = Array();
$inSect = false;
foreach($lines as $line){
$line = trim($line);
if(!$line || $line[0] == "#" || $line[0] == ";")
continue;
if($line[0] == "[" && $endIdx = strpos($line, "]")){
$inSect = substr($line, 1, $endIdx-1);
continue;
}
if(!strpos($line, '=')) // (We don't use "=== false" because value 0 is
not valid as well)
continue;
$tmp = explode("=", $line, 2);
if($ProcessSections && $inSect)
$return[$inSect][trim($tmp[0])] = ltrim($tmp[1]);
else
$return[trim($tmp[0])] = ltrim($tmp[1]);
}
return $return;
}
}
?>