PHPackages                             limitoco/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. limitoco/table-contents

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

limitoco/table-contents
=======================

Table of contents generation

2.1.0(9y ago)0207MITPHPPHP 7.1.\*

Since Mar 30Pushed 6y agoCompare

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

READMEChangelogDependenciesVersions (7)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)[![Build Status](https://camo.githubusercontent.com/308c940279ddce7e31899317aad0ab0485f9d58e711dd556d99a816f491ec83d/68747470733a2f2f7472617669732d63692e6f72672f6c75746465762f7461626c652d636f6e74656e74732e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/lutdev/table-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 7.1

### Installation

[](#installation)

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

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

```

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

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

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

Total

6

Last Release

3296d ago

Major Versions

1.0.x-dev → 2.0.02017-04-07

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

2.1.0PHP 7.1.\*

### Community

Maintainers

![](https://www.gravatar.com/avatar/c0c237ecbf599f35b9f360e5affdc77415827ad1bbc105eadb588d1e4f3da2a2?d=identicon)[mimshe](/maintainers/mimshe)

---

Top Contributors

[![lutdev](https://avatars.githubusercontent.com/u/9608305?v=4)](https://github.com/lutdev "lutdev (25 commits)")[![mimshe](https://avatars.githubusercontent.com/u/13119439?v=4)](https://github.com/mimshe "mimshe (5 commits)")

---

Tags

texttable contents

### Embed Badge

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

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

###  Alternatives

[froala/wysiwyg-editor

A beautiful jQuery WYSIWYG HTML rich text editor. High performance and modern design make it easy to use for developers and loved by users.

5.4k306.9k3](/packages/froala-wysiwyg-editor)[ckeditor/ckeditor

JavaScript WYSIWYG web text editor.

5234.2M76](/packages/ckeditor-ckeditor)[tinymce/tinymce

Web based JavaScript HTML WYSIWYG editor control.

1697.5M106](/packages/tinymce-tinymce)[unisharp/laravel-ckeditor

JavaScript WYSIWYG web text editor (for laravel).

377762.3k5](/packages/unisharp-laravel-ckeditor)[nojimage/twitter-text-php

A library of PHP classes that provide auto-linking and extraction of usernames, lists, hashtags and URLs from tweets.

1241.9M7](/packages/nojimage-twitter-text-php)[w8tcha/ckeditor-wordcount-plugin

WordCount Plugin for CKEditor Editor

77470.2k](/packages/w8tcha-ckeditor-wordcount-plugin)

PHPackages © 2026

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