PHP code example of smn / phsystem

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

    

smn / phsystem example snippets



$ph = new PlaceHolderSystem();
$ph->setPattern('I have 5 {fruit}');
$ph->addPlaceHolder('fruit', 'apple');
echo $ph->render(); // I have 5 apple



$ph = new PlaceHolderSystem();
$ph->setPattern('i learned how to count to {number}');
$ph->addPlaceHolder('number',function() {
 return 30;
});

echo $ph->render(); // i learned how to count to 30



class Num {

  public $val = 5;

}

$instance = new Num();
$ph = new PlaceHolderSystem();
$ph->setPattern('i learned how to count to {number}');
$ph->addPlaceHolder('number', function($param) {
 return $param->val;
}, [$instance]);
// Third parameter of addPlaceHolder method is an array with a list of parameters for callback function.

echo $ph->render(); // i learned how to count to 5

$instance->val = pow(2,16);
echo $ph->render(); // i learned how to count to 65536