Home > radius-php

radius-php

Radius-php is a project mainly written in PHP, based on the MIT license.

A cool template language for PHP.

Radius for PHP

This is my intent to port the Radius template language to PHP.

Radius is a powerful tag-based template language inspired by the template languages used in MovableType and TextPattern. It uses tags similar to XML, but can be used to generate any form of plain text (HTML, e-mail, etc...).

For PHP 5.3 or higher.

Usage

require_once '/path/to/radius/lib/Radius/Autoloader.php';
RadiusAutoloader::register();

// Create a context and define some tags
$context = new RadiusContext();
$context->defineTags(array(
    'hello' => function () {
        return 'Hello world';
    },
    'repeat' => function ($tag) {
        $number = $tag->getAttr('times', 1);
        $result = '';
        for ($i = 0; $i < $number; ++$i) {
            $result .= $tag->expand();
        }
        return $result;
    },
    ));

// Create a parser to parse tags that begin with 'r:'
$parser = new RadiusParser($context, 'r');

// Parse and outputs the result
echo $parser->parse("A small example:
<r:repeat times='3'>* <r:hello />!
</r:repeat>");

Output:

A small example:
* Hello world!
* Hello world!
* Hello world!

Development

This is not complete. If you feel interested and want to contribute, please contact me.