色尼玛亚洲综合影院,亚洲3atv精品一区二区三区,麻豆freexxxx性91精品,欧美在线91

php中配置文件操作 如config.php文件的讀取修改等操作

復制代碼 代碼如下:
<?php
$name="admin";//kkkk
$bb='234';
$db=4561321;
$kkk="admin";
?>

函數定義:
配置文件數據值獲?。篺unction getconfig($file, $ini, $type="string")
配置文件數據項更新:function updateconfig($file, $ini, $value,$type="string")
調用方式:
復制代碼 代碼如下:
getconfig("./2.php", "bb");//
updateconfig("./2.php", "kkk", "admin");

復制代碼 代碼如下:
<?php

//配置文件數據值獲取。
//默認沒有第三個參數時,按照字符串讀取提取''中或""中的內容
//如果有第三個參數時為int時按照數字int處理。
function getconfig($file, $ini, $type="string")
{
if ($type=="int")
{
$str = file_get_contents($file);
$config = preg_match("/" . $ini . "=(.*);/", $str, $res);
Return $res[1];
}
else
{
$str = file_get_contents($file);
$config = preg_match("/" . $ini . "=/"(.*)/";/", $str, $res);
if($res[1]==null)
{
$config = preg_match("/" . $ini . "='(.*)';/", $str, $res);
}
Return $res[1];
}
}

//配置文件數據項更新
//默認沒有第四個參數時,按照字符串讀取提取''中或""中的內容
//如果有第四個參數時為int時按照數字int處理。
function updateconfig($file, $ini, $value,$type="string")
{
$str = file_get_contents($file);
$str2="";
if($type=="int")
{
$str2 = preg_replace("/" . $ini . "=(.*);/", $ini . "=" . $value . ";", $str);
}
else
{
$str2 = preg_replace("/" . $ini . "=(.*);/", $ini . "=/"" . $value . "/";",$str);
}
file_put_contents($file, $str2);
}


//echo getconfig("./2.php", "bb", "string");
getconfig("./2.php", "bb");//
updateconfig("./2.php", "kkk", "admin");
//echo "<br/>".getconfig("./2.php", "name","string");

?>

復制代碼 代碼如下:
//完善改進版


/**
* 配置文件操作(查詢了與修改)
* 默認沒有第三個參數時,按照字符串讀取提取''中或""中的內容
* 如果有第三個參數時為int時按照數字int處理。
*調用demo
$name="admin";//kkkk
$bb='234';

$bb=getconfig("./2.php", "bb", "string");
updateconfig("./2.php", "name", "admin");
*/
function get_config($file, $ini, $type="string"){
if(!file_exists($file)) return false;
$str = file_get_contents($file);
if ($type=="int"){
$config = preg_match("/".preg_quote($ini)."=(.*);/", $str, $res);
return $res[1];
}
else{
$config = preg_match("/".preg_quote($ini)."=/"(.*)/";/", $str, $res);
if($res[1]==null){
$config = preg_match("/".preg_quote($ini)."='(.*)';/", $str, $res);
}
return $res[1];
}
}

function update_config($file, $ini, $value,$type="string"){
if(!file_exists($file)) return false;
$str = file_get_contents($file);
$str2="";
if($type=="int"){
$str2 = preg_replace("/".preg_quote($ini)."=(.*);/", $ini."=".$value.";",$str);
}
else{
$str2 = preg_replace("/".preg_quote($ini)."=(.*);/",$ini."=/"".$value."/";",$str);
}
file_put_contents($file, $str2);
}

php技術php中配置文件操作 如config.php文件的讀取修改等操作,轉載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

主站蜘蛛池模板: 镇雄县| 广德县| 大兴区| 横山县| 伊川县| 平江县| 项城市| 汉寿县| 肃宁县| 南充市| 通州市| 治多县| 卢湾区| 纳雍县| 当阳市| 德昌县| 大兴区| 延川县| 新和县| 枣强县| 徐汇区| 滨海县| 丰台区| 大宁县| 墨竹工卡县| 望江县| 高平市| 图木舒克市| 上虞市| 图木舒克市| 武强县| 绥宁县| 抚松县| 双柏县| 枣强县| 元江| 唐海县| 芜湖市| 乐山市| 普宁市| 镇原县|