四虎精品视频-四虎精品成人免费网站-四虎黄色网-四虎国产视频-国产免费91-国产蜜臀97一区二区三区

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

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

函數定義:
配置文件數據值獲取:function 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文件的讀取修改等操作,轉載需保留來源!

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

主站蜘蛛池模板: 苏西| 高钧贤| 丰满的阿2中文字幕| 文奎| 杨剑锋个人资料简介| 姐姐的秘密电影| 二年级100个词语| 38在线电影| 古曼 电影| 被抛弃的青春1982| 追捕演员表名单| 黄色网址视频在线播放| 《格林童话》白雪公主| 卓别林走路视频| 福田麻由子| 今天是你的生日bb伴奏正谱| leslie| 减肥喝什么榨汁减肥快| 韩世雅演过电影| 成人的性行为免费| 羞羞的| 高等学校毕业生登记表自我鉴定怎么写| 彭丹露点| 爱来爱去微电视完整| 我们的日子演员表| 阳光阿坝| 大红灯笼高高挂剧情介绍| river flows in you吉他谱| 电影百度百科| 同桌的你电影免费观看| 红灯停绿灯行电影观看| 爱情天梯| 正在恋爱中全集在线观看| 板谷由夏| 韩国伦理片在线观看免费| 蓝心妍电影| 北京卫视节目表今天| 男女男在线观看| 花样厨神 电影| 贝子鸟的叫声大全| 电影《邪》在线观看|