对形如config.php文件的读取,修改等操作
ed31d05440768161a870c8bc0f95f5d4
函数定义:
配置文件数据值获取:function getconfig($file, $ini, $type="string")
配置文件数据项更新:function updateconfig($file, $ini, $value,$type="string")
调用方式:
getconfig("./2.php", "bb");//
updateconfig("./2.php", "kkk", "admin");
1. [代码][PHP]代码
<?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"); ?>
2. [代码][PHP]代码
//完善改进版 /** * 配置文件操作(查询了与修改) * 默认没有第三个参数时,按照字符串读取提取''中或""中的内容 * 如果有第三个参数时为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); }

热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

mPDF
mPDF是一个PHP库,可以从UTF-8编码的HTML生成PDF文件。原作者Ian Back编写mPDF以从他的网站上“即时”输出PDF文件,并处理不同的语言。与原始脚本如HTML2FPDF相比,它的速度较慢,并且在使用Unicode字体时生成的文件较大,但支持CSS样式等,并进行了大量增强。支持几乎所有语言,包括RTL(阿拉伯语和希伯来语)和CJK(中日韩)。支持嵌套的块级元素(如P、DIV),

MinGW - 适用于 Windows 的极简 GNU
这个项目正在迁移到osdn.net/projects/mingw的过程中,你可以继续在那里关注我们。MinGW:GNU编译器集合(GCC)的本地Windows移植版本,可自由分发的导入库和用于构建本地Windows应用程序的头文件;包括对MSVC运行时的扩展,以支持C99功能。MinGW的所有软件都可以在64位Windows平台上运行。

SublimeText3 英文版
推荐:为Win版本,支持代码提示!

DVWA
Damn Vulnerable Web App (DVWA) 是一个PHP/MySQL的Web应用程序,非常容易受到攻击。它的主要目标是成为安全专业人员在合法环境中测试自己的技能和工具的辅助工具,帮助Web开发人员更好地理解保护Web应用程序的过程,并帮助教师/学生在课堂环境中教授/学习Web应用程序安全。DVWA的目标是通过简单直接的界面练习一些最常见的Web漏洞,难度各不相同。请注意,该软件中

VSCode Windows 64位 下载
微软推出的免费、功能强大的一款IDE编辑器