PHP code example of fastwf / interpolation

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

    

fastwf / interpolation example snippets



// test.php
// ...

use Fastwf\Interpolation\StringInterpolator;

$interpolator = new StringInterpolator();

echo $interpolator->interpolate(
    "Hello %{name} with injection escaped \%{name} or %{undefined} not injected.",
    ['name' => 'Fast Web Framework']
) . PHP_EOL;



///...
new StringInterpolator(true);


///...
new StringInterpolator(false, '#', '[', ']');


// test.php
// ...

use Fastwf\Interpolation\LexInterpolator;


$interpolator = new LexInterpolator();

echo $interpolator->interpolate(
    "Hello %{name} with injection escaped \%{name}.",
    ['name' => 'Fast Web Framework']
) . PHP_EOL;


// test.php
// ...

$interpolator = new LexInterpolator();

$interpolator->getEnvironment()
    ->setPipe('date', new PipeFunction(
        function ($date, $format) {
            return $date->format($format);
        })
    )
    ->setPipe('lower', new PipeFunction(
        function ($str) {
            return mb_strtolower($str);
        }
    ))
    ;

echo $interpolator->interpolate(
    "Today is %{ today | date('l jS F Y') | lower }.",
    ['today' => new DateTime('2022-03-16')]
) . PHP_EOL;


// ...

$interpolator = new LexInterpolator("#", "[", "]");

// ...
bash
$ php test.php
Hello Fast Web Framework with injection escaped %{name} or %{undefined} not injected.
bash
$ php test.php
Hello Fast Web Framework with injection escaped \%{name}.
bash
$ php test.php
Today is wednesday 16th march 2022.