PHP code example of nabeghe / risma

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

    

nabeghe / risma example snippets


use Nabeghe\Risma\Risma;

// The string IS the program:
// Combines variables, pipelines, built-in conditionals, and Direct Function Execution (@)
$template = 'Hi {user.trim.title}! You have {unread} unread {unread.plural("message", "messages")}. '
          . 'Server time: {@date("H:i")} | Status: {@phpversion.truncate(3, "").if_gte("8.0", "Modern 🚀 (%s)", "Legacy ⚠️ (%s)")}';

echo Risma::quick($template, [
    'user'   => '  sarah connor  ',
    'unread' => 5,
]);
// Output: Hi Sarah Connor! You have 5 unread messages. Server time: 14:30 | Status: Modern 🚀 (8.4)

use Nabeghe\Risma\Risma;

// 1. Instant static execution with direct functions (@) and pipelines:
echo Risma::quick(
    'Welcome {user.trim.title}! Server year: {@date("Y")} (PHP {@phpversion.truncate(3, "")})',
    ['user' => '  hadi  ']
);
// Output: Welcome Hadi! Server year: 2026 (PHP 8.3)

// 2. Instance execution with custom delimiters, shared globals, and direct execution:
$risma = (new Risma())
    ->share('app', 'CloudPortal')
    ->setDelimiters('[:', ':]');

echo $risma->render(
    '[:app:] © [:@date("Y"):] — Welcome, [:user.upper:]!',
    ['user' => 'Ali']
);
// Output: CloudPortal © 2026 — Welcome, ALI!