PHPackages                             lutdev/table-contents - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. lutdev/table-contents

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

lutdev/table-contents
=====================

Table of contents generation

4.0.0(5mo ago)5292[5 issues](https://github.com/lutdev/table-contents/issues)MITPHPPHP ^8.3CI passing

Since Mar 30Pushed 5mo ago2 watchersCompare

[ Source](https://github.com/lutdev/table-contents)[ Packagist](https://packagist.org/packages/lutdev/table-contents)[ Docs](https://github.com/lutdev/table-contents)[ RSS](/packages/lutdev-table-contents/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (5)DependenciesVersions (10)Used By (0)

[![License](https://camo.githubusercontent.com/e498eead712d82d9ee1af0a4850acd2e46ea48c48fb9ce5a3d2ab64f28f95b34/687474703a2f2f696d672e736869656c64732e696f2f3a6c6963656e73652d6d69742d626c75652e737667)](http://doge.mit-license.org)[![GitHub version](https://camo.githubusercontent.com/562927f42bc87b307294a0d0af56320ad5b0f49fc39b31f9bcbdaf5ed9b74e3b/68747470733a2f2f62616467652e667572792e696f2f67682f6c75746465762532467461626c652d636f6e74656e74732e737667)](https://badge.fury.io/gh/lutdev%2Ftable-contents)

About
-----

[](#about)

Package for generating table of contents for the text.

For example, you have next text:

```
Header first level
Some text here
Header second level
Some text here
Header fourth level
Some text here
Header third level
Some text here
```

Table of contents will be:

```
 - Header first level
    - Header second level
            - Header fourth level
         - Header third level

```

Table of contents support how strict headers nesting and free nesting, i.e. it can be: 1-2-4-3-6-2-4-1-3-7 or 1-2-3-2-4-1-2-3-4-3-5-2-3.

Table of contents work with only `` tags 1-10 levels (`h1` - `h10`).

Getting Started
---------------

[](#getting-started)

### Requirements

[](#requirements)

PHP 8.2

### Installation

[](#installation)

1. You can install the package using the [composer](https://getcomposer.org/).

```
"lutdev/table-contents": "^3.0"

```

Or install it by running this command in your project root:

```
composer require lutdev/table-contents

```

2. PHP class

```
use Lutdev\TOC\TableContents
```

or you can download package and include it via `require`

### Usage

[](#usage)

```
$tableContents = new TableContents();
```

```
//return string table contents
$tableContents->tableContents($text);
```

Table of contents have next structure:

```
"0": {
    "title": "Title",
    "link": "link"
},
"1": {
    "title": "Title",
    "link": "link"
},
"2": {
    "title": "Title",
    "link": "link"
    "subItems": {
        "3": {
            "title": "Title",
            "link": "link"
            "subItems": {
                "1": {
                    "subItems": {
                        "2": {
                            "subItems": {
                                "4": {
                                    "title": "Title",
                                    "link": "link"
                                },
                            }
                        }
                    }
                }
            }
        }
    }
}
```

- **Keys** (0,1,2,3,4) - header index number. **Keys** (1,2 subItems) - intermediate empty headers;
- **title** - title of the content item;
- **link** - anchor link. If text have few same headers links of them will be `-` (for example: link-1, link-2, link-3).

```
//Add ID attribute to the headers. Need for anchors.
$tableContents->headerLinks($text)
```

Feedback
--------

[](#feedback)

Thank you! If you have proposition or find error/bug write me, please.

License
-------

[](#license)

MIT

###  Health Score

43

—

FairBetter than 91% of packages

Maintenance51

Moderate activity, may be stable

Popularity13

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity84

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 93.5% 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 ~396 days

Recently: every ~783 days

Total

9

Last Release

163d ago

Major Versions

1.0.x-dev → 2.0.02017-04-07

2.1.x-dev → 3.0.02024-06-05

3.0.x-dev → 4.0.02025-12-02

PHP version history (4 changes)1.0.0PHP 5.6.\*

2.1.0PHP 7.1.\*

3.0.0PHP ^8.2

4.0.0PHP ^8.3

### Community

---

Top Contributors

[![lutdev](https://avatars.githubusercontent.com/u/9608305?v=4)](https://github.com/lutdev "lutdev (29 commits)")[![alutskevychcheck24](https://avatars.githubusercontent.com/u/176290747?v=4)](https://github.com/alutskevychcheck24 "alutskevychcheck24 (2 commits)")

---

Tags

phptable-of-contentstexttoc

### Embed Badge

![Health badge](/badges/lutdev-table-contents/health.svg)

```
[![Health](https://phpackages.com/badges/lutdev-table-contents/health.svg)](https://phpackages.com/packages/lutdev-table-contents)
```

PHPackages © 2026

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