PHP code example of cable8mm / toc

1. Go to this page and download the library: Download cable8mm/toc 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/ */

    

cable8mm / toc example snippets


namespace Cable8mm\Toc;

$markdown = '
- ## Prologue
    - [Release Notes](/docs/{{version}}/releases)
    - [Upgrade Guide](/docs/{{version}}/upgrade)
    - [Contribution Guide](/docs/{{version}}/contributions)
- ## Getting Started
    - [Installation](/docs/{{version}}/installation)
    - [Configuration](/docs/{{version}}/configuration)
';

$lines = Toc::of($markdown)->getLines();

foreach ($lines as $line) {
    // example "- ## Prologue"
    // example "    - [Release Notes](/docs/{{version}}/releases)"
    print $line->getTitle().PHP_EOL;
    //=> "Prologue"
    //=> "Release Notes"
    print $line->getLink().PHP_EOL;
    //=> null
    //=> "/docs/{{version}}/releases"
    print $line->getType().PHP_EOL;
    //=> ItemEnum::section
    //=> ItemEnum::page
    print $line->getDepth().PHP_EOL;
    //=> 1
    //=> 2
}