PHP code example of lutdev / table-contents

1. Go to this page and download the library: Download lutdev/table-contents library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

lutdev / table-contents example snippets


use Lutdev\TOC\TableContents

$tableContents = new TableContents();

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

"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"
                                },
                            }
                        }
                    }
                }
            }
        }
    }
}

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

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