PHP code example of tentwofour / twig

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

    

tentwofour / twig example snippets


$ex = new EmailEncodingExtension()
$ex->filter('[email protected]');

// => &#x66;&#x40;&#101;&#120;a&#x6d;&#x70;&#108;&#101;&#x2e;&#x63;&#111;&#109;

$ex = new DiffExtension();

// Will also work with multi-dimensional arrays

$a = [
    'key' => 'value',
];
$b = [
    'key' => 'value_2',
];
$ex->diff($a, $b);

// => [
//            0 => [
//                'd' => [
//                    'key' => 'value',
//                ],
//                'i' => [
//                    'key' => 'value_2',
//                ],
//            ],
//        ] 

$ex  = new DiffExtension();
$old = 'That&#39;s what it said on &quot;Ask Jeeves.&quot;';
$new = 'That&#39;s what it said on &quot;Dogpile.&quot;';

// Output to array
$ex->diffHtml($old, $new, 'array');

// => [
//            'old' => 'That&#39;s what it said on <del>&quot;Ask Jeeves.&quot;</del>',
//            'new' => 'That&#39;s what it said on <ins>&quot;Dogpile.&quot;</ins>',
//        ]

// Output to single string
$ex->diffHtml($old, $new, 'string');

// => 'That&#39;s what it said on <del>&quot;Ask Jeeves.&quot;</del><ins>&quot;Dogpile.&quot;</ins>';

$ex  = new InflectorExtension();
$string = 'camelCaseWordWith1Number';
$ex->camelCaseToCapitalizedWords($string)
// => 'Camel Case Word With 1 Number'
$ex->camelCaseToSentenceCasedWords($string)
// => 'Camel case word with 1 number'
$ex->camelCaseToLowerCasedWords($string)
// => 'camel case word with 1 number'

$ex = new MoneyExtension();
$ex->centsToDollars(1200);
// => '12.00'

$ex = new NumberExtension();
$ex->formatNumberToHumanReadable(1200000);
// => '1.2M'

$ex->formatNumberToHumanReadable(999.99);
// => '1K'

$ex->formatNumberToHumanReadable(3154.14159, 2, 'ceil');
// => 3.16K'

$ex->formatNumberToHumanReadable(3154.14159, 2, 'floor');
// => 3.15K