PHP code example of dhii / delimited-token-template

1. Go to this page and download the library: Download dhii/delimited-token-template 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/ */

    

dhii / delimited-token-template example snippets


use Dhii\Output\DelimitedTokenTemplate\Template;

$template = new Template('Hello, %user\%name%!', '%', '%', '\\'); // Note escaped delimiter
$template->render(['user%name' => 'johnny']); // Hello, johnny! 

use Dhii\Output\DelimitedTokenTemplate\Template;

$template = new Template('Hello, -user\-name__!', '-', '__', '\\'); // Note completely different delimiters
$template->render(['user-name' => 'johnny']); // Hello, johnny! 

use Dhii\Output\DelimitedTokenTemplate\TemplateFactory;

$factory= new TemplateFactory(':', '', ''); // Note absence of right delimiter and escape character
$profilePath = $factory->fromString('/users/:username/profile')
    ->render(['username' => 'johnny']); // '/users/johnny/profile'
$settingsPath = $factory->fromString('/users/:userId/settings')
    ->render(['userId' => '1234']); // '/users/1234/settings'