noczcore/ini
最新稳定版本:v1.1
Composer 安装命令:
composer require noczcore/ini
包简介
Read and write INI files in PHP.
README 文档
README
Read and write INI files/strings in PHP.
Inspired of Piwik/ini
Requirements
- parse_ini_string is enabled in php.ini
Installation
composer require noczcore/ini
Features
- Read INI files and INI strings
- Write INI files and INI strings
- Return a collection instead of a simple array
- Throws exceptions instead of PHP errors
- Better type supports (Exemple):
- Parse boolean (true/false, on/off, yes/no) to real PHP boolean
- Parse null to real PHP null
- Parse int/float to real PHP int/float
- Advanced parser (Exemple):
- A key with "[]" has an array value with many values
- A key with "." has an recursive array value with many values
Usage:
Read
use \NoczCore\Ini\IniReader; $reader = new IniReader(); $string = <<<INI [Section 1] foo = "bar" number_1 = 1 number_0 = 0 int = 10 float = 10.3 empty = "" null_ = null boolean_1 = true boolean_0 = false array[] = "string" array[] = 10.3 array[] = 1 array[] = 0 names.users[] = "NoczCore" names.administators[] = "John Doe" names.administators[] = "Jane Doe" [Section 2] foo = "bar" INI; // Read a string $array = $reader->readString($string); // Read a file $array = $reader->readFile('config.ini'); print_r($array->toArray());
####Return:
Array
(
[Section 1] => Array
(
[foo] => bar
[number_1] => 1
[number_0] => 0
[int] => 10
[float] => 10.3
[empty] => ""
[null_] => null
[boolean_1] => true
[boolean_0] => false
[array] => Array
(
[0] => string
[1] => 10.3
[2] => 1
[3] => 0
)
[names] => Array
(
[users] => Array
(
[0] => NoczCore
)
[administators] => Array
(
[0] => John Doe
[1] => Jane Doe
)
)
)
[Section 2] => Array
(
[foo] => bar
)
)
Write
use \NoczCore\Ini\IniWriter; $writer = new IniWriter(); // Write to a string $string = $writer->writeToString($array); // Write to a file $writer->writeToFile('config.ini', $array);
License
The Ini component is released under the MIT.
Contributing
To run the unit tests:
vendor/bin/phpunit
统计信息
- 总下载量: 321
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-10-14