php 站点使用XML文件做配置类
来源:互联网 发布:淘宝男鞋品牌排行榜 编辑:程序博客网 时间:2024/05/22 15:35
要用到,在网站上找了一个,然后自己整理成一个类..
<?php
/*
*PHP获取和设置XML节点,用于修改和读取站点配置文件
*2008-4-3
*LIQUAN
*eg.get config
*$c = new Configuration('config.xml');
*echo( $c->TemplateDirectory." " );
*
* set config
* $c = new Configuration('config.xml');
* $c->TemplateDirectory='test';
* $c->save();
*/
class Configuration
{
private $configFile;
private $items=array();
//构造函数
function __construct($configFile)
{
$this->configFile=$configFile;
$this->parse();
}
//获取属性
function __get($id)
{
return $this->items[$id];
}
//设置属性
function __set($key,$value)
{
$this->$items[$key]=$value;
}
//解析XML文件保存到数组
function parse()
{
$doc=new DOMDocument();
$doc->load($this->configFile);
$cn=$doc->getElementsByTagName('config');
$nodes=$cn->item(0)->getElementsByTagName('*');
foreach($nodes as $node)
{
$this->items[$node->nodeName]=$node->nodeValue;
}
}
//保存XML文件
function save()
{
$doc=new DOMDocument();
$doc->formatOutput=true;
$r=$doc->createElement('config');
$doc->appendChild($r);
foreach($this->items as $k=>$v)
{
$keyName=$doc->createElement($k);
$keyName->appendChild($doc->createTextNode($v));
$r->appendChild($keyName);
}
copy($this->configFile,$this->configFile.".bak");
$doc->save($this->configFile);
}
}
?>
/*
*PHP获取和设置XML节点,用于修改和读取站点配置文件
*2008-4-3
*LIQUAN
*eg.get config
*$c = new Configuration('config.xml');
*echo( $c->TemplateDirectory." " );
*
* set config
* $c = new Configuration('config.xml');
* $c->TemplateDirectory='test';
* $c->save();
*/
class Configuration
{
private $configFile;
private $items=array();
//构造函数
function __construct($configFile)
{
$this->configFile=$configFile;
$this->parse();
}
//获取属性
function __get($id)
{
return $this->items[$id];
}
//设置属性
function __set($key,$value)
{
$this->$items[$key]=$value;
}
//解析XML文件保存到数组
function parse()
{
$doc=new DOMDocument();
$doc->load($this->configFile);
$cn=$doc->getElementsByTagName('config');
$nodes=$cn->item(0)->getElementsByTagName('*');
foreach($nodes as $node)
{
$this->items[$node->nodeName]=$node->nodeValue;
}
}
//保存XML文件
function save()
{
$doc=new DOMDocument();
$doc->formatOutput=true;
$r=$doc->createElement('config');
$doc->appendChild($r);
foreach($this->items as $k=>$v)
{
$keyName=$doc->createElement($k);
$keyName->appendChild($doc->createTextNode($v));
$r->appendChild($keyName);
}
copy($this->configFile,$this->configFile.".bak");
$doc->save($this->configFile);
}
}
?>
- php 站点使用XML文件做配置类
- XML文件配置使用
- 【php】php中使用DOM类读取XML文件
- PHP 使用 XML Expat 解释xml文件
- include的返回值使用【作用1:使用php文件来做配置】
- 使用XML文件配置AX
- Apache + PHP 配置多站点
- apache php 多站点配置
- WAMPServer站点配置--php基础
- Nginx PHP多站点配置
- php中多个站点配置方法
- mac PHP多站点配置
- PHP操作XML做数据库的类
- PHP操作XML做数据库的类
- PHP使用SyntaxHighlighter显示xml文件
- php下使用SimpleXML 处理XML 文件
- php XML文件解释类
- PHP解析XML文件类
- php编写的ACCESS处理类
- 用C++修改本地安全策略
- java 中线程概念描述
- progressive jpeg 处理(转)
- Web自动化测试开源工具-Watir使用入门图解
- php 站点使用XML文件做配置类
- java 构造方法的继承
- Security Tutorials系列文章第六章:Validating User Credentials Against the Membership User Store
- 详细讲解Quartz.NET
- C#实现Web文件上传的两种方法
- Oracle中SQL语句的性能优化
- 构造 Create IRP
- 1.fstream.STL
- 在ubuntu 下安装insight