[PHP] 配置文件操作类 用程序设置配置文件config.php →→→→→进入此内容的聊天室

来自 , 2020-02-03, 写在 PHP, 查看 172 次.
URL http://www.code666.cn/view/e833e042
  1. /**
  2.  * 配置文件操作(查询了与修改)
  3.  * 默认没有第三个参数时,按照字符串读取提取''中或""中的内容
  4.  * 如果有第三个参数时为int时按照数字int处理。
  5.  *调用demo
  6.         $name="admin";//kkkk
  7.         $bb='234';
  8.        
  9.         $bb=getconfig("./2.php", "bb", "string");
  10.         updateconfig("./2.php", "name", "admin");
  11. */
  12. function get_config($file, $ini, $type="string"){
  13.         if(!file_exists($file)) return false;
  14.         $str = file_get_contents($file);
  15.         if ($type=="int"){
  16.                 $config = preg_match("/".preg_quote($ini)."=(.*);/", $str, $res);
  17.                 return $res[1];
  18.         }
  19.         else{
  20.                 $config = preg_match("/".preg_quote($ini)."=\"(.*)\";/", $str, $res);
  21.                 if($res[1]==null){     
  22.                         $config = preg_match("/".preg_quote($ini)."='(.*)';/", $str, $res);
  23.                 }
  24.                 return $res[1];
  25.         }
  26. }
  27.  
  28. function update_config($file, $ini, $value,$type="string"){
  29.         if(!file_exists($file)) return false;
  30.         $str = file_get_contents($file);
  31.         $str2="";
  32.         if($type=="int"){      
  33.                 $str2 = preg_replace("/".preg_quote($ini)."=(.*);/", $ini."=".$value.";",$str);
  34.         }
  35.         else{
  36.                 $str2 = preg_replace("/".preg_quote($ini)."=(.*);/",$ini."=\"".$value."\";",$str);
  37.         }
  38.         file_put_contents($file, $str2);
  39. }

回复 "配置文件操作类 用程序设置配置文件config.php"

这儿你可以回复上面这条便签

captcha