php读取配置文件函数

来源:互联网 发布:语嫣 淘宝网总裁 编辑:程序博客网 时间:2024/05/16 17:35

配置文件格式:

## Main Configuration File## it can be default or whatever language. Only greek are supported# from non latin alphabet languages# These attribute only apply for ldap not for sql#general_prefered_lang: elgeneral_prefered_lang_name: Greek## Uncomment this if normal attributes (not the ;lang-xx ones) in ldap# are utf8 encoded.##general_decode_normal_attributes: yes#general_base_dir: /usr/local/dialup_admingeneral_radiusd_base_dir: /usr/local/general_domain: my.domain

读取配置文件的php函数

if (!isset($config)){$ARR=file("admin.conf");foreach($ARR as $val) {$val=chop($val);if (ereg('^[[:space:]]*#',$val) || ereg('^[[:space:]]*$',$val))continue;list($key,$v)=split(":[[:space:]]*",$val,2);if (preg_match("/%\{(.+)\}/",$v,$matches)){$val=$config[$matches[1]];$v=preg_replace("/%\{$matches[1]\}/",$val,$v);}$config["$key"]="$v";}echo "<pre>";var_dump($config);}