earthit/paxml

Classes for emitting X[HT]ML.

2.0.0 2024-01-08 23:32 UTC

This package is auto-updated.

Last update: 2024-10-09 01:06:28 UTC


README

Build Status

PAXML: PHP Array [representation of] XML

This is a tiny library for emitting XML. Or XHTML.

Its intended use is to replace HTML/PHP template code with something easier to read and write and manipulate.

e.g. instead of

<p>Hi my name is <?php echo htmlspecialchars($name); ?></p>

you would construct a PAXML value like:

$value = ['p', 'Hi my name is ', $name];

and then output it using

EarthIT_PAXML::emit($value);

If you need a Nife_Blob, make one like so:

$blob = new EarthIT_PAXML_PAXMLBlob($value);

PAXML Values

Scalars represent text.

Arrays represent elements.

The 0th element of an array gives the tag name.

Subsequent numerically-keyed elements of an array give sub-tags.

String-keyed elements of an array give attribute values.

Examples

['p', 'style'=>'color: green', 'I like ', ['span', 'style'=>'color: red', 'food'], '.']

Will be emitted as:

<p style="color: green">I like <span style="color: red">food</span>.</p>