{"id":22425348,"url":"https://github.com/phppkg/ini","last_synced_at":"2025-03-27T06:15:11.343Z","repository":{"id":43447613,"uuid":"425186132","full_name":"phppkg/ini","owner":"phppkg","description":"💪 An enhanced INI format parser written in PHP.","archived":false,"fork":false,"pushed_at":"2024-04-02T02:35:10.000Z","size":69,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-07T09:48:59.633Z","etag":null,"topics":["encoder","ini-parser","ini-writer","php","php-ini"],"latest_commit_sha":null,"homepage":"https://phppkg.github.io/ini/","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/phppkg.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2021-11-06T07:49:08.000Z","updated_at":"2023-11-11T02:48:00.000Z","dependencies_parsed_at":"2023-11-14T07:29:06.636Z","dependency_job_id":"24eea6b5-2178-4ec3-a875-362b0b6e4daf","html_url":"https://github.com/phppkg/ini","commit_stats":{"total_commits":13,"total_committers":3,"mean_commits":4.333333333333333,"dds":"0.15384615384615385","last_synced_commit":"792fd3de0ee3838fe2b96e1da87183f3fa56abf2"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":"inherelab/php-pkg-template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phppkg%2Fini","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phppkg%2Fini/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phppkg%2Fini/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phppkg%2Fini/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/phppkg","download_url":"https://codeload.github.com/phppkg/ini/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245791967,"owners_count":20672671,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["encoder","ini-parser","ini-writer","php","php-ini"],"created_at":"2024-12-05T19:13:52.349Z","updated_at":"2025-03-27T06:15:11.301Z","avatar_url":"https://github.com/phppkg.png","language":"PHP","readme":"# INI\n\n[![License](https://img.shields.io/github/license/phppkg/ini?style=flat-square)](LICENSE)\n[![Php Version](https://img.shields.io/packagist/php-v/phppkg/ini?maxAge=2592000)](https://packagist.org/packages/phppkg/ini)\n[![GitHub tag (latest SemVer)](https://img.shields.io/github/tag/phppkg/ini)](https://github.com/phppkg/ini)\n[![Actions Status](https://github.com/phppkg/ini/workflows/Unit-Tests/badge.svg)](https://github.com/phppkg/ini/actions)\n\n💪 An enhanced `INI` format parser written in PHP.\n\n- auto convert data type, eg: `int, bool, float`\n- support encode data to INI string.\n- ignores commented lines that start with \";\" or \"#\"\n  - ignores broken lines that do not have \"=\"\n- supports array values and array value keys\n- enhance: supports inline list array value\n- enhance: supports multi line string. use `'''` or `\"\"\"`\n- enhance: supports add interceptor before collect value\n- TODO: support parse ENV var. `${SHELL | bash}`\n\n\u003e **[中文说明](README.zh-CN.md)**\n\n## Install\n\n- Required PHP 8.0+\n\n**composer**\n\n```bash\ncomposer require phppkg/ini\n```\n\n## Usage\n\nexample ini:\n\n```ini\n; comments line\n// comments line\n# comments line\n\nint = 23\nfloat = 34.5\nstr=ab cd\nbool=true\nempty-str = \n\n# support multi-line\nmulti-line = '''\nthis is\n  a multi\n line string\n'''\n\n# simple inline list array\ninlineList = [ab, 23, 34.5]\n\n# simple multi-line list array, equals the 'simpleList1'\nsimpleList[] = 567\nsimpleList[] = \"some value\"\n\n# simple multi-line list array\n[simpleList1]\n- = 567\n- = \"some value\"\n\n# simple k-v map\n[simpleMap]\nval_one = 567\nval_two = 'some value'\n\n# multi level list array\n[array]\narr_sub_key[] = \"arr_elem_one\"\narr_sub_key[] = \"arr_elem_two\"\narr_sub_key[] = \"arr_elem_three\"\n\n# multi level k-v map sub array\n[array_keys]\nval_arr_two[6] = \"key_6\"\nval_arr_two[some_key] = \"some_key_value\"\n```\n\n### Decode\n\nDecode from INI string.\n\n```php\nuse PhpPkg\\Ini\\Ini;\nuse Toolkit\\Stdlib\\Std\\Collection;\n\n$data = Ini::decode($ini);\nvdump($data);\n\n$cfg = Collection::new($data);\n$int = $cfg-\u003eget('int'); // 23\n```\n\n**Output**:\n\n```text\narray(13) {\n  [\"int\"]=\u003e int(23)\n  [\"float\"]=\u003e float(34.5)\n  [\"str\"]=\u003e string(5) \"ab cd\"\n  [\"bool\"]=\u003e bool(true)\n  [\"empty-str\"]=\u003e string(0) \"\"\n  [\"multi-line\"]=\u003e string(30) \"this is\n  a multi\n line string\"\n  [\"inlineList\"]=\u003e array(3) {\n    [0]=\u003e string(2) \"ab\"\n    [1]=\u003e int(23)\n    [2]=\u003e float(34.5)\n  }\n  [\"simpleList\"]=\u003e array(2) {\n    [0]=\u003e int(567)\n    [1]=\u003e string(10) \"some value\"\n  }\n  [\"simpleList1\"]=\u003e array(2) {\n    [0]=\u003e int(567)\n    [1]=\u003e string(10) \"some value\"\n  }\n  [\"simpleMap\"]=\u003e array(2) {\n    [\"val_one\"]=\u003e int(567)\n    [\"val_two\"]=\u003e string(10) \"some value\"\n  }\n  [\"array\"]=\u003e array(1) {\n    [\"arr_sub_key\"]=\u003e array(3) {\n      [0]=\u003e string(12) \"arr_elem_one\"\n      [1]=\u003e string(12) \"arr_elem_two\"\n      [2]=\u003e string(14) \"arr_elem_three\"\n    }\n  }\n  [\"array_keys\"]=\u003e array(1) {\n    [\"val_arr_two\"]=\u003e array(2) {\n      [6]=\u003e string(5) \"key_6\"\n      [\"some_key\"]=\u003e string(14) \"some_key_value\"\n    }\n  }\n}\n```\n\n### Decode file\n\n```php\n$data = Ini::decodeFile($iniFile);\n```\n\n## Encode\n\nEncode data to INI string.\n\n```php\n$data = [\n    'key0' =\u003e 'val0',\n    'key1' =\u003e 'val1',\n    'key2' =\u003e 'val2',\n    'key3' =\u003e 'val3',\n    'key4' =\u003e 'val4',\n    'arrKey' =\u003e [\n        'abc',\n        'def',\n    ],\n];\n\n$iniString = Ini::encode($data);\necho $iniString;\n```\n\n**Output**:\n\n```ini\nkey0 = val0\nkey1 = val1\nkey2 = val2\nkey3 = val3\nkey4 = val4\narrKey = [abc, def]\n```\n\n## License\n\n[MIT](LICENSE)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphppkg%2Fini","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphppkg%2Fini","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphppkg%2Fini/lists"}