Skip to content

Instantly share code, notes, and snippets.

@ExileofAranei
Last active May 12, 2022 18:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ExileofAranei/4a3e4a1b8756d995864fcde3b31391d4 to your computer and use it in GitHub Desktop.
Save ExileofAranei/4a3e4a1b8756d995864fcde3b31391d4 to your computer and use it in GitHub Desktop.
MODX snippet: wrap html content tables with a div
<?php
if (!$input) {
return '';
}
$doc = new DOMDocument();
$doc->loadHTML("\xEF\xBB\xBF" . $input, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
// Find all tables and wrap them with div.table-responsive element
$tables = $doc->getElementsByTagName('table');
$tableWrapper = $doc->createElement('div');
$tableWrapper->setAttribute('class', 'table-responsive');
foreach ($tables as $table) {
$wrapper = $tableWrapper->cloneNode();
$table->parentNode->replaceChild($wrapper, $table);
$wrapper->appendChild($table);
}
return html_entity_decode($doc->saveHTML());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment