PHP port of Markup.js
The test suite has also been ported, with some changes to take into account differences between PHP and JavaScript. Specifically:
- PHP has no equivalent of
undefined
- PHP can not call methods on primitives (like strings, ints)
In general, JavaScript's behavior is maintained, for example true + " " + false
in JS evaluates to "true false"
, whereas in PHP it would evaluate to "1 "
.
Requires (at least) PHP 5.4.
To use:
<?php
require('Mark.php');
use Markup\Mark;
$context = [
'name' => [ 'first' => 'John', 'last' => 'Doe' ],
];
$template = "{{name.last}}, {{name.first}}";
$result = Mark::up($template, $context);
?>