PHP Classes

hi, just a simple modification on your class (to solve some p...

Recommend this page to a friend!

      INI File Parser  >  All threads  >  hi, just a simple modification on...  >  (Un) Subscribe thread alerts  
Subject:hi, just a simple modification on...
Summary:Package rating comment
Messages:1
Author:Pedro Alves
Date:2008-06-02 14:12:13
 

 

Pedro Alves rated this package as follows:

Utility: Not sure
Consistency: Not sure
Examples: Not sure

  1. hi, just a simple modification on...   Reply   Report abuse  
Picture of Pedro Alves Pedro Alves - 2008-06-02 14:12:13
hi, just a simple modification on your class (to solve some problems on the indexed keys)


class parseini
{
private $result = array();
private $key=false;
public function parse($file)
{
if ($lines = file($file))
{
$ini_key=array();
foreach ($lines as $l)
{
if (!preg_match('/[0-9a-z]/i', $l) or preg_match('/^#/', $l))
{
continue;
}
if (preg_match('/(\[)(.*)(\])/i', $l,$keys))
{
$this->key=$keys[2];
}
else
{
preg_match('/(.*)=(.*)/', $l, $t);
if ($this->key)
{
$result[$this->key][$t[1]]=rtrim($t[2],"\r\n");
}
else
{
$result[$ini_key[2]][$t[1]]=rtrim($t[2],"\r\n");
}
}
}
}
else
{
die('File Error!!');
}
return $result;
}
}