PHPackages                             yosymfony/toml - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. yosymfony/toml

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

yosymfony/toml
==============

A PHP parser for TOML compatible with specification 0.4.0

v1.0.4(7y ago)2081.7M↓11.4%31[6 issues](https://github.com/yosymfony/Toml/issues)[2 PRs](https://github.com/yosymfony/Toml/pulls)20MITPHPPHP &gt;=7.1CI failing

Since Jun 2Pushed 5y ago4 watchersCompare

[ Source](https://github.com/yosymfony/Toml)[ Packagist](https://packagist.org/packages/yosymfony/toml)[ Docs](http://github.com/yosymfony/toml)[ RSS](/packages/yosymfony-toml/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (2)Versions (14)Used By (20)

TOML parser for PHP
===================

[](#toml-parser-for-php)

A PHP parser for [TOML](https://github.com/toml-lang/toml) compatible with [TOML v0.4.0](https://github.com/toml-lang/toml/releases/tag/v0.4.0).

[![Build Status](https://camo.githubusercontent.com/cb4c23914470efcad5457d0212ba5590f70fe15c498f9da55b6d303931717132/68747470733a2f2f7472617669732d63692e6f72672f796f73796d666f6e792f746f6d6c2e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/yosymfony/toml)[![Latest Stable Version](https://camo.githubusercontent.com/b09aff4de4fa74426e6fc62fb41b89c9a9fb26ae3378e5de2fc7045542fab04a/68747470733a2f2f706f7365722e707567782e6f72672f796f73796d666f6e792f746f6d6c2f762f737461626c652e706e67)](https://packagist.org/packages/yosymfony/toml)[![Total Downloads](https://camo.githubusercontent.com/461cf607d8aba5235c1e6f0196e7e4fd6d6fb7c2f06610f607083037ae3d9053/68747470733a2f2f706f7365722e707567782e6f72672f796f73796d666f6e792f746f6d6c2f646f776e6c6f6164732e706e67)](https://packagist.org/packages/yosymfony/toml)

Support:

[![Gitter](https://camo.githubusercontent.com/abe08b740a4156153736f791393ec4da6619c4be73212e75769f52edacc0e2b5/68747470733a2f2f6261646765732e6769747465722e696d2f4a6f696e253230436861742e737667)](https://gitter.im/yosymfony/Toml?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)

Installation
------------

[](#installation)

**Requires PHP &gt;= 7.1.**

Use [Composer](http://getcomposer.org/) to install this package:

```
composer require yosymfony/toml
```

Usage
-----

[](#usage)

You can parse an inline TOML string or from a file:

To parse an inline TOML string:

```
use Yosymfony\Toml\Toml;

$array = Toml::Parse('key = [1,2,3]');

print_r($array);
```

To parse a TOML file:

```
$array = Toml::ParseFile('example.toml');

print_r($array);
```

Additionally, methods `parse` and `parseFile` accept a second argument called `resultAsObject` to return the result as an object based on `stdClass`.

```
$object = Toml::Parse('key = [1,2,3]', true);
```

### TomlBuilder

[](#tomlbuilder)

You can create a TOML string with TomlBuilder. TomlBuilder uses a *fluent interface* for more readable code:

```
    use Yosymfony\Toml\TomlBuilder;

    $tb = new TomlBuilder();

    $result = $tb->addComment('Toml file')
        ->addTable('data.string')
        ->addValue('name', "Toml", 'This is your name')
        ->addValue('newline', "This string has a \n new line character.")
        ->addValue('winPath', "C:\\Users\\nodejs\\templates")
        ->addValue('literal', '@') // literals starts with '@'.
        ->addValue('unicode', 'unicode character: ' . json_decode('"\u03B4"'))

        ->addTable('data.bool')
        ->addValue('t', true)
        ->addValue('f', false)

        ->addTable('data.integer')
        ->addValue('positive', 25, 'Comment inline.')
        ->addValue('negative', -25)

        ->addTable('data.float')
        ->addValue('positive', 25.25)
        ->addValue('negative', -25.25)

        ->addTable('data.datetime')
        ->addValue('datetime', new \Datetime())

        ->addComment('Related to arrays')

        ->addTable('data.array')
        ->addValue('simple', array(1,2,3))
        ->addValue('multiple', array(
            array(1,2),
            array('abc', 'def'),
            array(1.1, 1.2),
            array(true, false),
            array( new \Datetime()) ))

        ->addComment('Array of tables')

        ->addArrayOfTable('fruit')                            // Row
            ->addValue('name', 'apple')
            ->addArrayOfTable('fruit.variety')
                ->addValue('name', 'red delicious')
            ->addArrayOfTable('fruit.variety')
                ->addValue('name', 'granny smith')
        ->addArrayOfTable('fruit')                            // Row
            ->addValue('name', 'banana')
            ->addArrayOfTable('fruit.variety')
                ->addValue('name', 'plantain')
        ->getTomlString();    // Generate the TOML string
```

The result:

```
#Toml file

[data.string]
name = "Toml" #This is your name
newline = "This string has a \n new line character."
winPath = "C:\\Users\\nodejs\\templates"
literal = ''
unicode = "unicode character: δ"

[data.bool]
t = true
f = false

[data.integer]
positive = 25 #Comment inline.
negative = -25

[data.float]
positive = 25.25
negative = -25.25

[data.datetime]
datetime = 2013-06-10T21:12:48Z

#Related to arrays

[data.array]
simple = [1, 2, 3]
multiple = [[1, 2], ["abc", "def"], [1.1, 1.2], [true, false], [2013-06-10T21:12:48Z]]

# Array of tables

[[fruit]]
name = "apple"

[[fruit.variety]]
name = "red delicious"

[[fruit.variety]]
name = "granny smith"

[[fruit]]
name = "banana"

[[fruit.variety]]
name = "plantain"
```

#### Limitations

[](#limitations)

The `TomlBuilder` class is an utility to get Toml strings that has the following limitations:

- Only admits `basic strings` and `literal strings`.

Deprecated method
-----------------

[](#deprecated-method)

The following method will be eliminated in version 2.0.0

- \[TomlBuilder\] **addArrayTables**

Contributing
------------

[](#contributing)

When Contributing code to this library, you must follow its coding standards. Toml follows [PSR-2 coding style](https://www.php-fig.org/psr/psr-2/). To ensure the CS, you can use the CLI tool [PHP-CS-Fixer](https://github.com/FriendsOfPHP/PHP-CS-Fixer).

Unit tests
----------

[](#unit-tests)

You can run the unit tests with the following command:

```
$ cd toml
$ composer test
```

License
-------

[](#license)

This library is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT).

###  Health Score

47

—

FairBetter than 94% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity59

Moderate usage in the ecosystem

Community36

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 83.2% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~157 days

Recently: every ~65 days

Total

13

Last Release

2840d ago

Major Versions

v0.3.3 → v1.0.02017-11-18

0.x-dev → v1.0.12018-02-05

PHP version history (2 changes)v0.1.0PHP &gt;=5.3.0

v1.0.0PHP &gt;=7.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/3321099?v=4)[Yo! Symfony](/maintainers/yosymfony)[@yosymfony](https://github.com/yosymfony)

---

Top Contributors

[![yosymfony](https://avatars.githubusercontent.com/u/3321099?v=4)](https://github.com/yosymfony "yosymfony (168 commits)")[![victorpuertas](https://avatars.githubusercontent.com/u/3154875?v=4)](https://github.com/victorpuertas "victorpuertas (27 commits)")[![sagebind](https://avatars.githubusercontent.com/u/2192863?v=4)](https://github.com/sagebind "sagebind (2 commits)")[![prisis](https://avatars.githubusercontent.com/u/2716058?v=4)](https://github.com/prisis "prisis (2 commits)")[![tg666](https://avatars.githubusercontent.com/u/24430186?v=4)](https://github.com/tg666 "tg666 (1 commits)")[![githubjeka](https://avatars.githubusercontent.com/u/874234?v=4)](https://github.com/githubjeka "githubjeka (1 commits)")[![h4cc](https://avatars.githubusercontent.com/u/2981491?v=4)](https://github.com/h4cc "h4cc (1 commits)")

---

Tags

configurationphptomlparsertomlmojombo

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/yosymfony-toml/health.svg)

```
[![Health](https://phpackages.com/badges/yosymfony-toml/health.svg)](https://phpackages.com/packages/yosymfony-toml)
```

###  Alternatives

[nikic/php-parser

A PHP parser written in PHP

17.4k902.6M1.8k](/packages/nikic-php-parser)[doctrine/lexer

PHP Doctrine Lexer parser library that can be used in Top-Down, Recursive Descent Parsers.

11.2k910.8M118](/packages/doctrine-lexer)[erusev/parsedown

Parser for Markdown.

15.0k151.8M732](/packages/erusev-parsedown)[league/commonmark

Highly-extensible PHP Markdown parser which fully supports the CommonMark spec and GitHub-Flavored Markdown (GFM)

3.0k404.0M702](/packages/league-commonmark)[masterminds/html5

An HTML5 parser and serializer.

1.8k242.8M229](/packages/masterminds-html5)[sabberworm/php-css-parser

Parser for CSS Files written in PHP

1.8k191.2M65](/packages/sabberworm-php-css-parser)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
