<?php
|
namespace ConfigReader;
|
#´´½¨ÈÕÆÚ£º2012-4-13 ÏÂÎç4:10:48
|
#×÷Õߣºxcc
|
#ÅäÖÃÎļþ¶ÁÈ¡Æ÷
|
Class ConfigReader
|
{
|
private $m_sErrInfo;
|
private $m_sFile;
|
private $m_CfgArry;
|
|
function __construct($file)
|
{
|
$this->m_sFile = $file;
|
$this->m_sErrInfo = "No Err!";
|
$this->m_CfgArry=false;
|
}
|
|
//¶ÁÈ¡ÅäÖÃÎļþ
|
function load ()
|
{
|
if (file_exists($this->m_sFile) == false)
|
{
|
$this->m_sErrInfo = "Not Exit File:".$this->m_sFile;
|
return false;
|
}
|
$this->m_CfgArry = parse_ini_file ($this->m_sFile, true);
|
|
if( $this->m_CfgArry==false )
|
{
|
$this->m_sErrInfo="parse ini file:".$this->m_sFile." error!";
|
return false;
|
}
|
return true;
|
}
|
|
//ÅжÏÊÇ·ñÓÐÖ¸¶¨Section´æÔÚ
|
function IsSectionExist( $strSection )
|
{
|
if( $this->m_CfgArry==false )
|
{
|
return false;
|
}
|
|
return array_key_exists( $strSection , $this->m_CfgArry );
|
}
|
|
//»ñȡָ¶¨sectionºÍidentËùÖ¸ÏòµÄÊý¾Ý£¬Èç¹û²»´æÔÚ£¬Ôòµ÷ÓÃGetErrInfo()»ñÈ¡´íÎóÐÅÏ¢
|
public function GetData($section, $ident, &$ret)
|
{
|
$ret = "";
|
if (array_key_exists($section, $this->m_CfgArry))
|
{
|
if (array_key_exists($ident, $this->m_CfgArry[$section]))
|
{
|
$ret = $this->m_CfgArry[$section][$ident];
|
}
|
else
|
{
|
$this->m_sErrInfo = "ConfigFile:".$this->m_sFile." Can't Find ident:".$ident." in section:".$section;
|
return false;
|
}
|
}
|
else
|
{
|
$this->m_sErrInfo = "ConfigFile:".$this->m_sFile." Can't Find section:".$section;
|
return false;
|
}
|
return true;
|
}
|
|
public function GetErrInfo()
|
{
|
return $this->m_sErrInfo;
|
}
|
}
|
|
?>
|