PHP code example of lightster / named-sprintf

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

    

lightster / named-sprintf example snippets




use Lstr\Sprintf\Sprintf;

$sprintf->sprintf(
    "Hello %(first_name)s %(last_name)s\n",
    ['first_name' => 'Matt', 'last_name' => 'Light']
);



$sprintf = new Sprintf();

echo $sprintf->sprintf(
    "PI is approximately %(pi).5f, or %(pi).8f if you need more accuracy\n",
    ['pi' => pi()]
);

echo $sprintf->sprintf(
    "The type is optional and defaults to string (e.g. 's'): %(name)\n",
    ['name' => 'Typeless!']
);


$sprintf = new Sprintf(
    function ($name, callable $values) {
        $value = $values($name);

        if (is_array($value)) {
            return implode(' ', $value);
        }

        return $value;
    }
);

echo $sprintf->sprintf(
    "Middleware %(action_words) to pre-process %(what)!\n",
    [
        'action_words' => ['can', 'be', 'used'],
        'what'         => 'parameters',
    ]
);



use Lstr\Sprintf\Middleware\Cli\Bundle as CliBundle;

$sprintf = new Sprintf(new CliBundle());

echo $sprintf->sprintf(
    "php bin/some-cli %(sub-command) %(long-options) %(short-options)",
    [
        'sub-command'  => 'commit',
        'long-options' => [
            'message' => 'Showing off a CLI command',
            'author'  => 'Matt',
        ],
        'short-options' => [
            'a' => null,
        ],
    ]
) . "\n";