PHP Classes
Icontem

File: LittleIniParser.php


  Search   All class groups All class groups   Latest entries Latest entries   Top 10 charts Top 10 charts   Newsletter Newsletter   Blog Blog   Forums Forums   Help FAQ Help FAQ  
  Login   Register  
Recommend this page to a friend! ReTweet ReTweet Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Andrey Nikishaev  >  Little INI Parser  >  LittleIniParser.php  
File: LittleIniParser.php
Role: Class source
Content type: text/plain
Description: Little Ini Parser Class
Class: Little INI Parser
Parse INI files and store values in arrays
 

Contents

Class file image Download
<?php
/**
 *     Little Ini Parser
 *
 *     LICENSE
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * @category   Little
 * @package    Little_Ini_Parser
 * @copyright  Copyright (c) 2008-2020 Nikishaev Andrey (http://andreynikishaev.livejournal.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 * @version    1.1
 */

class Little_Ini_Parser {
    
        static 
$declared;
        
        
/**
         * Loads configuration from the configuration files
         *
         * @param string $pathes    - pathes to the configuration files
         * @param string $sep_k        - key separator string
         * @param string $sep_v        - value separator string
         * @return array            - parsed configuration the configuration files
         */
        
        
public function parse($pathes$sep_k='.'$sep_v=',') {
            
$conf=array();
            foreach(
$pathes as $mp){
                
$conf+=self::getArr($mp$sep_k$sep_v);
            }
            return 
$conf;
        }    
        
        
/**
         * Loads configuration from the configuration file 
         * and returns the associative array
         *
         * @param string $path     - path to the configuration file
         * @param string $sep_k    - key separator string
         * @param string $sep_v    - value separator string
         * @return array        - parsed configuration
         */
        
        
private function getArr($path$sep_k='.'$sep_v=',') {
            if(!
self::$declared) {
                function 
tr($value) {
                    return 
trim($value);
                }
                
self::$declared=true;
            }
            
            
$out=array();
            
$conf=parse_ini_file($path,true);
            foreach(
$conf as $k=>$v) {
                    
$out[$k]=array();
                    foreach(
$v as $key=>$val) {
                        
$keys=explode($sep_k,$key);
                            
$link=&$out[$k];
                        foreach(
$keys as $key_sep) {    
                            
$link=&$link[$key_sep];
                        }    
                        if(
eregi(',',$val)) {
                            
$values=explode($sep_v,$val);
                            
array_walk($keys,'tr');
                            
$link=$values;
                        } else {
                            
$link=$val;
                        }
                    }
            
            }
            
            return 
$out;
        
        }
}

 
  Advertise on this site Advertise on this site   Site map Site map   Statistics Statistics   Site tips Site tips   Privacy policy Privacy policy   Contact Contact  

For more information send a message to :
info at phpclasses dot org.
Copyright (c) Icontem 1999-2009 PHP Classes - PHP Class Scripts
  PHP Book Reviews - Reviews of books and other products