当前位置:网站首页>PHP读取ini文件并修改内容写入
PHP读取ini文件并修改内容写入
2022-07-05 04:21:00 【Casual_1573】
读取ini文件并改写数据写入到ini
updateTime.ini
#更新时间记录
[fileUpdateTime]
time = ""
[sqlOtherUpdateTime]
time = "2022-06-08"
[sqlUpdateTime]
time = "2022-05-15"//方法一
function write_ini_file($array, $file) {
$res = array();
foreach($array as $key => $val) {
if(is_array($val)) {
$res[] = "[$key]";
foreach($val as $skey => $sval) {
$res[] = "$skey = ".(is_numeric($sval) ? $sval : '"'.$sval.'"');
}
} else {
$res[] = "$key = ".(is_numeric($val) ? $val : '"'.$val.'"');
}
}
safefilerewrite($file, implode("\r\n", $res));
}
function safefilerewrite($fileName, $dataToSave) {
if ($fp = fopen($fileName, 'w')) {
$startTime = microtime(TRUE);
do {
$canWrite = flock($fp, LOCK_EX);
if(!$canWrite) usleep(round(rand(0, 100)*1000));
} while ((!$canWrite)and((microtime(TRUE)-$startTime) < 5));
if ($canWrite) {
fwrite($fp, $dataToSave);
flock($fp, LOCK_UN);
}
fclose($fp);
}
}
$timeInfo = parse_ini_file('updateTime.ini',true);
$timeInfo['sqlOtherUpdateTime']['time'] = date("Y-m-d", time());
write_ini_file($timeInfo, "updateTime.ini");//方法二
function write_ini_file_tow($assoc_arr, $path, $has_sections=FALSE) {
$content = "";
if ($has_sections) {
foreach ($assoc_arr as $key=>$elem) {
$content .= "[".$key."]\n";
foreach ($elem as $key2=>$elem2) {
if(is_array($elem2))
{
for($i=0;$i<count($elem2);$i++)
{
$content .= $key2."[] = \"".$elem2[$i]."\"\n";
}
}
else if($elem2=="") $content .= $key2." = \n";
else $content .= $key2." = \"".$elem2."\"\n";
}
}
}
else {
foreach ($assoc_arr as $key=>$elem) {
if(is_array($elem))
{
for($i=0;$i<count($elem);$i++)
{
$content .= $key."[] = \"".$elem[$i]."\"\n";
}
}
else if($elem=="") $content .= $key." = \n";
else $content .= $key." = \"".$elem."\"\n";
}
}
if (!$handle = fopen($path, 'w')) {
return false;
}
$success = fwrite($handle, $content);
fclose($handle);
return $success;
}
$timeInfo = parse_ini_file('updateTime.ini',true);
$timeInfo['sqlOtherUpdateTime']['time'] = date("Y-m-d", time());
write_ini_file_tow($timeInfo, 'updateTime.ini', true);边栏推荐
- Moco is not suitable for target detection? MsrA proposes object level comparative learning target detection pre training method SOCO! Performance SOTA! (NeurIPS 2021)...
- About the prompt loading after appscan is opened: guilogic, it keeps loading and gets stuck. My personal solution. (it may be the first solution available in the whole network at present)
- Machine learning decision tree
- Phpmailer reported an error: SMTP error: failed to connect to server: (0)
- Online text line fixed length fill tool
- Containerd series - what is containerd?
- Longyuan war "epidemic" 2021 network security competition web easyjaba
- Threejs clicks the scene object to obtain object information, and threejs uses raycaster to pick up object information
- [popular science] basic knowledge of thermal design: heat dissipation analysis of 5g optical devices
- Containerd series - detailed explanation of plugins
猜你喜欢

Why do big companies such as Baidu and Alibaba prefer to spend 25K to recruit fresh students rather than raise wages by 5K to retain old employees?
![[popular science] basic knowledge of thermal design: heat dissipation analysis of 5g optical devices](/img/45/380e739f5eed33626c363756f814d3.png)
[popular science] basic knowledge of thermal design: heat dissipation analysis of 5g optical devices

Ctfshow web entry code audit

Network layer - forwarding (IP, ARP, DCHP, ICMP, network layer addressing, network address translation)

C language course setting: cinema ticket selling management system

American 5g open ran suffered another major setback, and its attempt to counter China's 5g technology has failed

How to get the first few pieces of data of each group gracefully

技术教程:如何利用EasyDSS将直播流推到七牛云?

Threejs Internet of things, 3D visualization of factory

Why can't all browsers on my computer open web pages
随机推荐
Threejs realizes the drawing of the earth, geographical location annotation, longitude and latitude conversion of world coordinates threejs coordinates
Study notes 7
【虚幻引擎UE】打包报错出现!FindPin错误的解决办法
A应用唤醒B应该快速方法
【虛幻引擎UE】實現UE5像素流部署僅需六步操作少走彎路!(4.26和4.27原理類似)
[phantom engine UE] only six steps are needed to realize the deployment of ue5 pixel stream and avoid detours! (the principles of 4.26 and 4.27 are similar)
OWASP top 10 vulnerability Guide (2021)
学习MVVM笔记(一)
电源管理总线 (PMBus)
Here comes the Lantern Festival red envelope!
Number of possible stack order types of stack order with length n
kubernetes集群之调度系统
Three level linkage demo of uniapp uview u-picker components
What is the reason why the webrtc protocol video cannot be played on the easycvr platform?
After the deployment of web resources, the navigator cannot obtain the solution of mediadevices instance (navigator.mediadevices is undefined)
level17
Threejs factory model 3DMAX model obj+mtl format, source file download
Machine learning decision tree
Judge whether the stack order is reasonable according to the stack order
【虚幻引擎UE】运行和启动的区别,常见问题分析