PHP code example of chrissileinus / template-php

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

    

chrissileinus / template-php example snippets


Chrissileinus\Template\Str::placeholders('a', 'b');

// @returns string: "This is my value: nic"
Chrissileinus\Template\Str::replace("This is my value: {0}", ['nic']);

// @returns string: "My name is Christian Backus"
Chrissileinus\Template\Str::replace(
  "My name is {name} {surname}",
  [
    'name' => 'Christian',
    'surname' => 'Backus'
  ]
);

// @returns string: "My name is Christian and her name is Aline"
Chrissileinus\Template\Str::replace(
  "My name is {my.name} and her name is {her.name}",
  [
    'my' => ['name' => 'Christian'],
    'her' => ['name' => 'Aline']
  ]
);

// @returns string: "My name is Christian and her name is Aline"
Chrissileinus\Template\Str::replace(
  "My name is {my.name} and her name is {her.name}",
  [
    'my' => ['name' => 'Christian']
  ],
  [
    'her' => ['name' => 'Aline']
  ]
);

// @returns string: "My name is chris and my age is 041 [ 83.40]"
Chrissileinus\Template\Str::replaceFormat(
  "My name is {user.name} and my age is {age%03d} [{weight%6.2f}]",
  [
    'user' => [
      'name' => "chris"
    ],
    'age' => 41,
    'weight' => 83.4,
  ]
);

// @returns string: "My name is chris and my age is 041 [ 83.40]"
Chrissileinus\Template\Str::replaceFormat(
  "My name is {user.name&user.color} and {my&user.color} age is {age&f_blue} {[{weight%6.2f}]&test.style}",
  [
    'user' => [
      'name' => "chris"
    ],
    'age' => 41,
    'weight' => 83.4,
  ],
  [
    'user' => [
      'color' => "f_yellow"
    ],
    'test' => [
      'style' => "bold,f_magenta"
    ]
  ]
);