php读取ini配置文件属性
ini的内容格式如下,请根据自己的INI,格式修改下段程序.
autostart = false
font_size =
font_color = red
===================
function get_ini_file($file_name = "demo.ini"){
$str=file_get_contents($file_name);//读取ini文件存到一个字符串中.
$ini_list = explode("\r\n",$str);//按换行拆开,放到数组中.
$ini_items = array();
foreach($ini_list as $item){
$one_item = explode("=",$item);
if(isset($one_item[])&&isset($one_item[])) $ini_items[trim($one_item[])] = trim($one_item[]); //存成key=>value的形式.
}
return $ini_items;
} function get_ini_item($ini_items = null,$item_name = ''){//获得INI条目的值.
if(empty($ini_items)) return "";
else return $ini_items[$item_name];
} $ini_items = get_ini_file("demo.ini"); echo get_ini_item($ini_items,'font_size'); //输出获得的值.
<?php
//写ini文件
function write_ini_file($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 .= $key2."[] = \"".$elem[$i]."\"\n";
}
}
else if($elem=="") $content .= $key2." = \n";
else $content .= $key2." = \"".$elem."\"\n";
}
}
if (!$handle = fopen($path, 'w'))
{
return false;
}
if (!fwrite($handle, $content))
{
return false;
}
fclose($handle);
return true;
} //用法
//
$sampleData = array(
'first' => array(
'first-1' => 1,
'first-2' => 2,
'first-3' => 3,
'first-4' => 4,
'first-5' => 5,
),
'second' => array(
'second-1' => 1,
'second-2' => 2,
'second-3' => 3,
'second-4' => 4,
'second-5' => 5,
));
write_ini_file($sampleData, './data.ini', true); //读ini文件
public function readini($name)
{
if (file_exists(SEM_PATH.'init/'.$name))
{
$data = parse_ini_file(SEM_PATH.'init/'.$name,true);
if ($data)
{
return $data;
}
}
else
{
return false;
}
}
https://www.cnblogs.com/guaidaodark/archive/2015/06/02/4547876.html
php读取ini配置文件属性的更多相关文章
- golang 读取 ini配置信息
package main //BY: 29295842@qq.com//这个有一定问题 如果配置信息里有中文就不行//[Server] ;MYSQL配置//Server=localhost ...
- Java读取ini配置
本文转载地址: http://www.cnblogs.com/Jermaine/archive/2010/10/24/1859673.html 不够通用,呵呵. 读取ini的配置的格式如下 ...
- 部分转 Java读取ini配置
转自: http://www.cnblogs.com/Jermaine/archive/2010/10/24/1859673.html 读取ini的配置的格式如下: [section1] key1=v ...
- boost::property_tree 读取ini配置
应用场景: 在后端服务器项目开发中,需要初始化一个Socket服务器,需要IP地址与对应端口号等参数:另外还可能因为对接数据库,就还需要数据库的相关配置参数,如我使用的是MySql数据库,就需要数据库 ...
- 转 python3 读取 ini配置文件
在代码中经常会通过ini文件来配置一些常修改的配置.下面通过一个实例来看下如何写入.读取ini配置文件. 需要的配置文件是: 1 [path] 2 back_dir = /Users/abc/Pych ...
- 读取设置config.ini配置
class CSenseIni { /************************************************************************/ /*写操作 * ...
- .ini配置读取
ini文件的格式 格式 INI文件由节.键.值组成. 节 [section] 参数(键=值) name=value 注解 注解使用分号表示(;).在分号后面的文字,直到该行结尾都全部为注解. ...
- 两个由于php.ini配置错误导致的报错:ajax图片上传报错和exec报错
遇到了两个由于php.ini配置错误导致的报错:ajax图片上传报错和exec报错 首先第一个: 在做一个用ajax图片上传的功能中,php报了这样一个错误:File upload error - u ...
- C#读取ini文件的方法
最近项目用到ini文件,读取ini文件,方法如下: using System; using System.Collections.Generic; using System.Linq; using S ...
随机推荐
- (转)thymeleaf中的判断总结
判断String字符串,添加引号 th:class="${flag=='forum.html'}?'active'" 判断boolean类型,注意不能当成字符串处理,不能添加引号 ...
- Ubuntu ssh-keygen 生成公钥并添加到远程服务器上
1. 在本地生成公钥, ssh-keygen -t RSA -b 800 2. cd /root/.ssh 3. ssh-copy-id -i id_rsa.pub 远程服务器IP 这一步需要输入远 ...
- NiftyNet开源平台使用
NiftyNet是一款开源的卷积神经网络平台,专门针对医学图像处理分析,上一篇博客已经详细介绍了这个平台,接下来让我简单介绍一下目前我了解到的使用方法.更详细的使用方法.以及配置过程请查看NiftyN ...
- 2018-6-20-随笔-SQL Server中乱码
SQL Server中乱码解决方案: 在Sql Server2005英文版中,如果未对Varchar类型的字段进行设置,那么很多朋友会发现向数据库中插入记录时,如果对应的varchar类型字段 的值为 ...
- Hibernate中Restrictions查询用法(转)
Restrictions查询用法 HQL运算符 QBC运算符 含义 = Restrictions.eq() 等于equal <> Restrictions.ne() 不等于not equa ...
- BZOJ.3532.[SDOI2014]LIS(最小割ISAP 退流)
BZOJ 洛谷 \(LIS\)..经典模型? 令\(f_i\)表示以\(i\)结尾的\(LIS\)长度. 如果\(f_i=1\),连边\((S,i,INF)\):如果\(f_i=\max\limits ...
- 1099 Lottery
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1099 英文水平太差了,题目实在是不知道是什么意思,然后看了其他高手写的思路,才看明白. 题意,收集n张彩票 ...
- ab测试工具
我们可以模拟100个并发用户,对一个页面发送1000个请求 输入命令:ab -n1000 -c100 http://www.jb51.net/ 结果: ##首先是apache的版本信息 This is ...
- svn提交后 添加注释
svn 提交后添加注释 第一步: 第二步: 第三步:提交就可以了. 注意:如果svn服务器管理员没有激活pre-revprop-change这个hook,会出现 需要让svn服务器管理员没有激活pre ...
- 使用8.0版本jdbc驱动连接数据库操作
转自:https://blog.csdn.net/qq_41734885/article/details/80562815 首先,我居然不能用navicat客户端连接上mysql8.0数据库报1251 ...