earthit / paxml
Classes for emitting X[HT]ML.
Installs: 12 347
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 18
Forks: 0
Open Issues: 0
Requires
- php: >=8.1
Requires (Dev)
- earthit/php-common: ^2.0.1
- phpunit/phpunit: ~10.5.5
README
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>