Skip to content

Instantly share code, notes, and snippets.

@alxy
Created April 26, 2014 16:07
Show Gist options
  • Save alxy/11323893 to your computer and use it in GitHub Desktop.
Save alxy/11323893 to your computer and use it in GitHub Desktop.
<?php
function generateHTML($elements, $formaters = array()) {
$doc = new DOMDocument;
$div = $doc->createElement('div');
$div->setAttribute('class', 'review-item');
$doc->appendChild($div);
$table = $doc->createElement('table');
$div->appendChild($table);
foreach ($elements as $name => $value) {
$tr = $doc->createElement('tr');
$tr->setAttribute('height', '10');
if (array_key_exists($name, $formaters)) {
$value = $formaters[$name]($value);
}
echo($value);
$tr->appendChild($doc->createElement('td', $name));
$tr->appendChild($doc->createElement('td', $value));
$table->appendChild($tr);
}
// $doc->formatOutput = true;
return $doc->saveHTML();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment