代码如下:

$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");

//配置文件数据值获取。

//默认没有第三个参数时,按照字符串读取提取''中或""中的内容

//如果有第三个参数时为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 "
".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程序里的configini_php中配置文件操作 如config.php文件的读取修改等操作相关推荐

  1. php中配置文件操作config.php文件的读取修改等操作

    定义和用法 fputs() 函数写入文件(可安全用于二进制文件). fputs() 函数是 fwrite() 函数的别名. //file 必需.规定要写入的打开文件. //string 必需.规定要写 ...

  2. python对文件的读操作有哪些方法-Python中文件的读取和写入操作

    从文件中读取数据 读取整个文件 这里假设在当前目录下有一个文件名为'pi_digits.txt'的文本文件,里面的数据如下: 3.1415926535 8979323846 2643383279 wi ...

  3. python对文件的读操作方法有哪些-Python中文件的读取和写入操作

    从文件中读取数据 读取整个文件 这里假设在当前目录下有一个文件名为'pi_digits.txt'的文本文件,里面的数据如下: 3.1415926535 8979323846 2643383279 wi ...

  4. python pandas 读取excel 去重某一列_Python中Pandas读取修改excel操作攻略(代码示例)...

    本篇文章给大家带来的内容是关于Python中Pandas读取修改excel操作攻略(代码示例),有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助. 环境:python 3.6.8 以某米赛 ...

  5. python pandas excel 修改列_Python中Pandas读取修改excel操作攻略(代码示例)

    本篇文章给大家带来的内容是关于Python中Pandas读取修改excel操作攻略(代码示例),有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助. 环境:python 3.6.8 以某米赛 ...

  6. python3 文件的读取和通用操作

    import os           # 当前操作目录,os.chdir() 切换操作目录 >>> import os >>> os.getcwd() 'C:\\ ...

  7. Python Pandas读取修改excel操作攻略​​​​​​​

    Python Pandas读取修改excel操作攻略 环境:python 3.6.8 以某米赛尔号举个例子吧: >>> pd.read_excel('1.xlsx', sheet_n ...

  8. Nginx —— nginx的命令行控制(nginx的启动与停止、重载配置文件、回滚日志文件、平滑升级等操作)

    在linux中,需要使用命令来控制Nginx服务器的启动与停止.重载配置文件.回滚日志文件.平滑升级等行为. 默认情况下,nginx被安装在目录/usr/local/nginx中,其二进制文件路径为/ ...

  9. java操作office和pdf文件java读取word,excel和pdf文档内容

    在平常应用程序中,对office和pdf文档进行读取数据是比较常见的功能,尤其在很多web应用程序中.所以今天我们就简单来看一下Java对word.excel.pdf文件的读取.本篇博客只是讲解简单应 ...

最新文章

  1. LogiCORE IP Clocking Wizard 之 Core Architecture(时钟IP核的核架构介绍)
  2. Vue计算属性和监听属性
  3. 一次 Nacos 的踩坑记录!
  4. 加了try-catch也能自动定位到异常代码[VS Tips]
  5. 1MySQL是面向对象型数据库_数据库及MySQL基础(1)
  6. zabbix 安装(yum)
  7. [Android ] linux命令英文缩写的含义(方便记忆)
  8. i5700 预,链接
  9. 条件概率与条件概率举例
  10. u2000网管服务器系统安装,U2000网管预安装后无法登陆
  11. P2168 [NOI2015]荷马史诗
  12. excel表格打印每页都有表头_excel单页表格打印带连续页码的多页
  13. CentOS + Mongodb 搭建NodeBB [转载翻译]
  14. WPF 按钮动画效果制作
  15. LoRa模块无线通信技术在距离测量和定位上的应用——东胜物联
  16. KNOWN_HOSTS处理
  17. 求助!win10这段时间在使用其间经常性的系统中断这个进程100%cpu的情况
  18. Kryo:快速、高效的序列化框架
  19. docker 删除映像_创建自己的Docker映像(技术提示#57)
  20. 基于stm32的超声波HC-SR04测距仪含距离报警(温度补偿)

热门文章

  1. Javaweb环境配置,使用2014MyEclipse全过程详解!搭建JDK环境,Tomcat环境!破解2014MyEclipse。
  2. 从零开始一起学习SLAM | 为啥需要李群与李代数?
  3. CNN模型之MobileNet
  4. APS:大型多模态室内摄像机定位系统
  5. python 多线程编程之_thread模块
  6. hadoop day 3
  7. bash shell的一些基本概念
  8. 【Joomla】K2 Item 页面添加 Module
  9. Cruise Control
  10. 解决 ERROR: Couldn't connect to Docker daemon at http+docker://localunixsocket - is it running?