hxp
2025-06-04 f4a514d5ac952110da846636ecbb9de951eaf3d2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?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;
    }
}
 
?>