对形如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 無盡。

熱門文章

熱工具

WebStorm Mac版
好用的JavaScript開發工具

MantisBT
Mantis是一個易於部署的基於Web的缺陷追蹤工具,用於幫助產品缺陷追蹤。它需要PHP、MySQL和一個Web伺服器。請查看我們的演示和託管服務。

SecLists
SecLists是最終安全測試人員的伙伴。它是一個包含各種類型清單的集合,這些清單在安全評估過程中經常使用,而且都在一個地方。 SecLists透過方便地提供安全測試人員可能需要的所有列表,幫助提高安全測試的效率和生產力。清單類型包括使用者名稱、密碼、URL、模糊測試有效載荷、敏感資料模式、Web shell等等。測試人員只需將此儲存庫拉到新的測試機上,他就可以存取所需的每種類型的清單。

VSCode Windows 64位元 下載
微軟推出的免費、功能強大的一款IDE編輯器

Atom編輯器mac版下載
最受歡迎的的開源編輯器