background image

php 操作配置文件的实例

本文介绍下,在

php 编程中,获取、修改、删除配置文件的实例代码,有需要的朋友参考下。

本节内容:
php 操作配置文件的例子
1,php 管理配置文件的类
代码示例

:

<?php 
define("__CR__", "\r\n"); //回车换行符 
 
class fileConfigOp 

/*配置文件*/ 
var $file = ''; 
 
/**
* 构造函数
*
* @param string $file 配置文件
* @return null
*/ 
function __construct($file = '') 

    if (empty($file)) { 
        die("Not specify config file!"); 
    } 
    if (!file_exists($file)) { 
        die("File '{$this->file}' does not exists!"); 
    } 
    if (!is_readable($file)) { 
        die("File '{$this->file}' is not readable!"); 
    } 
    $this->file =& $file; 

 
/**
* 获取配置文件的变量
*
* @param string $varName 变量名称
* @return string|array 如果指定变量名称,则只返回该变量对应的值,否则返回所有变量所
对应的一维数组
*/ 
function get($varName = '')