天天躁日日躁狠狠躁AV麻豆-天天躁人人躁人人躁狂躁-天天澡夜夜澡人人澡-天天影视香色欲综合网-国产成人女人在线视频观看-国产成人女人视频在线观看

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文件的讀取修改等操作,轉載需保留來源!

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

主站蜘蛛池模板: 国产精品www视频免费看 | 亚洲国产高清视频在线观看 | 91九色视频在线观看 | 蜜桃传媒在线播放 | 成人毛片手机版免费看 | 东京热影院 | 第一次处破女完整版电影 | 91精品欧美一区二区三区 | 高H短篇辣肉纯肉 | 暖暖日本手机免费完整版在线观看 | 国产在线精品亚洲一品区 | 亚洲无人区码二码三码区别图 | 亚洲精品国产专区91在线 | 97超碰免费人妻中文 | 海角社区在线视频播放观看 | 黄色三级三级三级免费看 | 久久国产精品高清一区二区三区 | 国产色精品久久人妻无码看片软件 | 91国偷自产一区二区三区 | 印度性hd18| 高H短篇辣肉纯肉 | 抽插的日日液液H | 孕妇高潮抽搐喷水30分钟 | 双性精跪趴灌满h室友4p | 纯肉宠文高h一对一 | www.三级| 精品午夜久久福利大片免费 | 国产精品日韩欧美一区二区三区 | 久久AV亚洲精品一区无码网 | xx69欧美| 狠狠色噜噜狠狠狠狠米奇777 | 国产亚洲精品福利视频 | 毛片大片免费看 | 久久久久久88色偷偷 | 亚洲伊人久久大香线蕉综合图片 | 久久人妻无码毛片A片麻豆 久久人妻熟女中文字幕AV蜜芽 | 精品无人区一区二区三区 | 永久精品免费影院在线观看网站 | 美女网站免费看 | 日本一卡二卡三卡四卡无卡免费播放 | 娇妻中日久久持久久 |