INI ”就是英文 “initialization”的头三个字母的缩写;当然INI file的后缀名也不一定是".ini"也可以是".cfg",".conf ”或者是".txt"

INI文件的格式很简单,最基本的三个要素是:parameters,sections和comments。

什么是parameters?

INI所包含的最基本的“元素”就是parameter;每一个parameter都有一个name和一个value,如下所示:

name = value

什么是sections ?

所有的parameters都是以sections为单位结合在一起的。所有的section名称都是独占一行,并且sections名字都被方括号包围着([ and ])。在section声明后的所有parameters都是属于该section。对于一个section没有明显的结束标志符,一个section的开始就是上一个section的结束,或者是end of the file。Sections一般情况下不能被nested,当然特殊情况下也可以实现sections的嵌套。

section如下所示:

[section]

什么是comments ?

在INI文件中注释语句是以分号“;”开始的。所有的所有的注释语句不管多长都是独占一行直到结束的。在分号和行结束符之间的所有内容都是被忽略的。

注释实例如下:

;comments text

当然,上面讲的都是最经典的INI文件格式,随着使用的需求INI文件的格式也出现了很多变种;

INI实例1:

test.ini

; 通用配置,文件后缀.ini
[common]application.directory = APPLICATION_PATH  "/application"
application.dispatcher.catchException = TRUE; 数据库配置
resources.database.master.driver = "pdo_mysql"
resources.database.master.hostname = "127.0.0.1"
resources.database.master.port = 3306
resources.database.master.database = "database"
resources.database.master.username = "username"
resources.database.master.password = "password"
resources.database.master.charset = "UTF8"; 生产环境配置
[product : common]; 开发环境配置
[develop : common]resources.database.slave.driver = "pdo_mysql"
resources.database.slave.hostname = "127.0.0.1"
resources.database.slave.port = 3306
resources.database.slave.database = "test"
resources.database.slave.username = "root"
resources.database.slave.password = "123456"
resources.database.slave.charset = "UTF8"; 测试环境配置
[test : common]

读取文件:

<?php$config=parse_ini_file('./test.ini');print_r($config);

测试打印:

$ php -f test.php
Array
([application.directory] => APPLICATION_PATH/application[application.dispatcher.catchException] => 1[resources.database.master.driver] => pdo_mysql[resources.database.master.hostname] => 127.0.0.1[resources.database.master.port] => 3306[resources.database.master.database] => database[resources.database.master.username] => username[resources.database.master.password] => password[resources.database.master.charset] => UTF8[resources.database.slave.driver] => pdo_mysql[resources.database.slave.hostname] => 127.0.0.1[resources.database.slave.port] => 3306[resources.database.slave.database] => test[resources.database.slave.username] => root[resources.database.slave.password] => 123456[resources.database.slave.charset] => UTF8
)

INI实例2,多维数组:

env.conf

;应用程序配置
[application]
env=develop[dblist]
dbtype[]=test
dbtype[]=dev
dbtype[]=v1
dbtype[]=release
dbtype[]=online

读取示例:

<?php//第二个参数设置为true,读取多维数组
$config=parse_ini_file('./env.conf',TRUE);print_r($config);

测试打印:

$ php -f test.php
Array
([application] => Array([env] => develop)[dblist] => Array([dbtype] => Array([0] => test[1] => dev[2] => v1[3] => release[4] => online)))

JS读取ini文件

<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"><title>Document</title><script src="./js/jquery-2.1.0.min.js"></script>
</head><body><input class="file" type="file" onchange="jsReadFiles(this.files)" /><script>//js 读取文件function jsReadFiles(files) {if (files.length) {var file = files[0];var reader = new FileReader();//new一个FileReader实例// if (/text+/.test(file.type)) {//判断文件类型,是不是text类型//     console.log('txt')//     reader.onload = function () {//         console.log(this.result)//         console.log(typeof this.result)//         $('body').append('<pre>' + this.result + '</pre>');//     }//     reader.readAsText(file);// } else if (/image+/.test(file.type)) {//判断文件是不是imgage类型//     console.log('image')//     reader.onload = function () {//         console.log(this.result)//         console.log(typeof this.result)//         $('body').append('<img src="' + this.result + '"/>');//     }//     reader.readAsDataURL(file);// }if (file.name.indexOf('.ini') != -1) {console.log('ini')reader.onload = function () {console.log(this.result)console.log(parseINIString(this.result))console.log(typeof this.result)$('body').append('<pre>' + this.result + '</pre>');}reader.readAsText(file);} else {console.log('hhhh')}}}// http://www.manongjc.com/article/130183.html// http://www.gimoo.net/t/1907/5d23e1e9ab4e2.html// 本文实例讲述了JavaScript实现解析INI文件内容的方法。分享给大家供大家参考,具体如下:// .ini 是Initialization File的缩写,即初始化文件,ini文件格式广泛用于软件的配置文件。// INI文件由节、键、值、注释组成。// 根据node.js版本的node-iniparser改写了个JavaScript函数来解析INI文件内容,传入INI格式的字符串,返回一个json object。function parseINIString(data) {var regex = {section: /^\s*\s*([^]*)\s*\]\s*$/,param: /^\s*([\w\.\-\_]+)\s*=\s*(.*?)\s*$/,comment: /^\s*;.*$/};var value = {};var lines = data.split(/\r\n|\r|\n/);var section = null;lines.forEach(function (line) {if (regex.comment.test(line)) {return;} else if (regex.param.test(line)) {var match = line.match(regex.param);if (section) {value[section][match[1]] = match[2];} else {value[match[1]] = match[2];}} else if (regex.section.test(line)) {var match = line.match(regex.section);console.log(match)value[match[0]] = {};section = match[0];} else if (line.length == 0 && section) {section = null;};});return value;}</script>
</body></html>

引用了文章:ini文件格式和读取 - 简书

input[tyle="file"]样式修改及上传文件名显示

默认的上传样式我们总觉得不太好看,根据需求总想改成和上下结构统一的风格……

实现方法和思路:1.在input元素外加a超链接标签2.给a标签设置按钮样式3.设置input[type='file']为透明,并定位,覆盖在a上面

html代码:

<a class="input-file input-fileup" href="javascript:;">+ 选择文件<input size="100" type="file" name="file" id="file">
</a>
<div class="fileerrorTip1"></div>
<div class="showFileName1"></div>

css代码:

.input-file{display: inline-block;position: relative;overflow: hidden;text-align: center;width: auto;background-color: #2c7;border: solid 1px #ddd;border-radius: 4px;padding: 5px 10px;font-size: 12px;font-weight: normal;line-height: 18px;color:#fff;text-decoration: none;
}
.input-file input[type="file"] {position: absolute;top: 0;right: 0;font-size: 14px;background-color: #fff;transform: translate(-300px, 0px) scale(4);height: 40px;opacity: 0;filter: alpha(opacity=0);}

此时并不能显示上传的文件名,如需显示出上传的文件名需要js来处理

js代码:

<script>$(function(){$(".input-fileup").on("change","input[type='file']",function(){var filePath=$(this).val();if(filePath.indexOf("jpg")!=-1 || filePath.indexOf("png")!=-1){$(".fileerrorTip1").html("").hide();var arr=filePath.split('\');var fileName=arr[arr.length-1];$(".showFileName1").html(fileName);}else{$(".showFileName1").html("");$(".fileerrorTip1").html("您未上传文件,或者您上传文件类型有误!").show();return false}})})</script>

效果:

摘自文章:input[tyle="file"]样式修改及上传文件名显示 - 走看看

ini文件格式和读取相关推荐

  1. delphi xe4 ini文件不能读取的解决方法

    今天发现用inifiles下 tinifile.readstring方法突然不能读数据了,结果把ini文件格式由utf-8改成unicode后就能正常读取了. 转载于:https://www.cnbl ...

  2. ini配置文件的读取

    .ini 文件是Initialization File的缩写,即初始化文件.是windows的系统配置文件所采用的存储格式,统管windows的各项配置,一般用户就用windows提供的各项图形化管理 ...

  3. Go语言从INI配置文件中读取需要的值

    生命不息,学习不止 题外话 INI配置文件 从 INI 文件中取值 getValue() 函数 你以为结束了 题外话 清晨第一缕阳光打在我的脸上,我从我席梦思床垫上爬起,拿起我的iPhone56,定了 ...

  4. Access导入文本文件的Schema.ini文件格式

    Schema.ini格式如下(参考:MSDN主题 Schema.ini File): Schema.ini用于提供文本数据中的记录规格信息.每个Schema.ini的条目用于指明表的5个特征之一: 文 ...

  5. java 修改ini文件_Java读取和修改ini配置文件

    /** * 修改ini配置文档中变量的值 * @param file 配置文档的路径 * @param section 要修改的变量所在段名称 * @param variable 要修改的变量名称 * ...

  6. java enum转ini_JAVA中用XML实现INI文件格式的解决方

    这几天写个数据库查询分析器,要用到XML记录用户注册的数据库连接地址.端口等信息,最开始想用java的propertie类来完成.但propertie不支持[小结名--键值名--键值]这种结构,如果要 ...

  7. MATLAB对ply文件格式的读取和显示

    转自:https://blog.csdn.net/lafengxiaoyu/article/details/60574150 在网上搜索这个题目可以找到一些类似的文章,其来源大致都是http://pe ...

  8. go语言的ini文件配置读取

    项目中我们可能经常要读取配置文件.那么如何读取自己写的配置文件呢?答案是反射.下面举例mysql的配置文件读取的具体操作代码. 1.首先建立myconfig.ini文件,并写入以下内容: [mysql ...

  9. java 修改ini文件_java读取和修改ini配置文件 | 学步园

    /* * ConfigurationFile.java * * Created on 2009年4月15日, 下午1:36 * * To change this template, choose To ...

最新文章

  1. 关于(警告: No configuration found for the specified action)解决方案
  2. Spring_Hibernate整合准备
  3. ZOJ 1057 Undercut(简单模拟)
  4. python一元加号_Python一元方程解算系统(需要Sympy库支持)
  5. 三岁小孩开发搜索引擎,搜索引擎白热化[原创]
  6. Git正解 脱水版 【7. Git命令】
  7. 将python随机森林模型保存到文件
  8. Spark调优—参数调优
  9. APM监控--(六)Dapper,大规模分布式系统的跟踪系统
  10. java元组_Java中元组的使用
  11. 一个码稿人自述:什么样的文档产品适合我?|深度吐槽
  12. php控制梯形图,如何画梯形图? plc梯形图怎么画?如何画plc梯形图
  13. 坚持连续背单词一年是什么体验
  14. php的seeder是什么,轻松学Laravel6数据填充之方式一Seeder填充
  15. Debian参考手册(3-4)
  16. matlab中disparity,matlab disparity函数
  17. rabbitmq的web管理界面-密码管理
  18. create方法 eslint关闭_react create-react-app使用less 及关闭eslint
  19. 【Python】字典遍历(dict遍历)
  20. Unity引擎中的C#语言学习的笔记(1)

热门文章

  1. ThinkPHP6使用七牛云存储,不改代码,改下配置就上七牛
  2. java本地Cache缓存的使用
  3. 如何激活预装的office
  4. MySQL之建表时[Err] 1050 - Table ‘users‘ already exists异常解决方法
  5. CListCtrl基本用法
  6. 如何发好外贸邮件,看亚马逊SES邮件服务商怎么说?
  7. 8080端口被占用处理方法
  8. 〖Python零基础入门篇(60)〗 - 随机模块 - random
  9. m4s格式,多线程爬B站视频
  10. selenium如何执行网页脚本