PHP code example of ermarian / xbbcode

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

    

ermarian / xbbcode example snippets




use \Ermarian\XBBCode\Processor\CallbackTagProcessor;
use \Ermarian\XBBCode\Processor\TemplateTagProcessor;
use \Ermarian\XBBCode\Tree\TagElementInterface;
use \Ermarian\XBBCode\XBBCodeParser;

$parser = new XBBCodeParser([
  'b' => new TemplateTagProcessor('<strong>{content}</content>'),
  'url' => new CallbackTagProcessor(function(TagElementInterface $tag) {
    $url = htmlspecialchars($tag->getOption());
    return '<a href="' . $url . '>' . $tag->getContent() . '</a>';
  }),
]);

print $parser->parse('[b]Hello [url=http://example.com]world[/url]![/b]')->render();