PHP code example of onesimus-systems / recoder

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

    

onesimus-systems / recoder example snippets


Recoder Recoder::_construct(string $open = null, string $close = null)
bool Recoder::register(string $shortcode, callable $func)
bool Recoder::registerAlias(string $shortcode, string $aliasedCode)
string Recoder::process(string $text [, mixed $... ])
null Recoder::unregister([string $shortcode = null])
null Recoder::setDelimiters(string $open, string $close = null)

$sc = new Recoder();
$sc->register('name', function(array $options) { return $options['_code']; });
$sc->register('content', function(array $options) { return $options['_content']; });

$parsedText = $sc->process('[name]'); // Return: name
$parsedText = $sc->process('[content]Some content[/content]'); // Return: Some content

$sc->unregister('content'); // Unregister one code
$sc->unregister(); // Unregister all codes

$sc->registerAlias('newCode', 'aliasedCode'); // Now [newCode] will do the samething as [aliasedCode]

$sc->register('list-args', function(array $options) {
    $r = [];
    foreach($options as $key => $val) {
        if ($key[0] !== '_') {
            $r []= "$key:$val";
        }
    }
    return implode(' & ', $r);
});

$parsedText = $sc->process('[list-args arg1=val1 arg2="Some value"]');
// Return: arg1:val1 & arg2:Some value

$sc->register('code', function(array $options, $someObj) {
    return $someObj->someMethod();
});

$parsedText = $sc->process('[code]', $obj);
// Everything after the first argument is passed to the handlers

$sc = new Recoder('{', '}'); // Code syntax is now {code arg=val}