Home > Backend Development > PHP Tutorial > An example of code for php to read configuration files

An example of code for php to read configuration files

WBOY
Release: 2016-07-25 08:51:57
Original
800 people have browsed it
  1. /**
  2. * Read configuration file
  3. * by bbs.it-home.org
  4. */
  5. if (!isset($config)){
  6. $ARR=file("admin.conf");
  7. foreach($ARR as $val) {
  8. $val=chop($val);
  9. if (ereg('^[[:space:]]*#',$val) || ereg('^[[:space:]]*$',$val))
  10. continue;
  11. list($key,$v)=split(":[[:space:]]*",$val,2);
  12. if (preg_match("/%{(.+)}/",$v,$matches)){
  13. $val=$config[$matches[1]];
  14. $v=preg_replace("/%{$matches[1]}/",$val,$v);
  15. }
  16. $config["$key"]="$v";
  17. }
  18. echo "
    ";  
  19. var_dump($config);
  20. }
复制代码


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template