PHP code example of l3aro / html-toc

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

    

l3aro / html-toc example snippets


use l3aro\HtmlToc\HtmlToc;

public function show(HtmlToc $toc) {
    $content = <<<HTML
        <h2>This is heading H2</h2>
        <h3>This is heading H3</h3>
        <h4>This is heading H4</h4>
        <h2>This is heading H2</h2>
    HTML;

    $markup = $toc->from($content);
    $markupContent = $markup->getMarkup();
    $tableOfContent = $markup->getTableOfContent();

    $htmlOut  = "<div class='content'>" . $markupContent . "</div>";
    $htmlOut .= "<div class='toc'>" . $tableOfContent . "</div>";

    return $htmlOut;
 }

use l3aro\HtmlToc\Facades\HtmlToc;

public function show() {
    $content = <<<HTML
        <h2>This is heading H2</h2>
        <h3>This is heading H3</h3>
        <h4>This is heading H4</h4>
        <h2>This is heading H2</h2>
    HTML;

    $markup = HtmlToc::from($content);
    $markupContent = $markup->getMarkup();
    $tableOfContent = $markup->getTableOfContent();

    $htmlOut  = "<div class='content'>" . $markupContent . "</div>";
    $htmlOut .= "<div class='toc'>" . $tableOfContent . "</div>";

    return $htmlOut;
}