PHP code example of off-by-n / shortcode-templates

1. Go to this page and download the library: Download off-by-n/shortcode-templates 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/ */

    

off-by-n / shortcode-templates example snippets


(new ShortcodeParser)->parse($inputString);

function process($chunks = [])
{
    $output = '';
    foreach ($chunks as $chunk) {
        if ($chunk->isShortcode()) {
            $shortcode = $chunk->asShortcode();
            if ($shortcode->getName() == 'raw') {
                $output .= $shortcode->getInnerSource();
            } else {
                $output .= process($shortcode->getChildren());
            }
        } else {
            $output .= $chunk;
        }
    }

    return $output;
}