So I'm working on a little web app for my colleagues and I'm loading messages from a label of their choosing from the gmail inboxes into the web app. Everything is working properly when the messages are basic, just text, etc.
However, as soon as I am dealing with "real-world" messages full of JS and CSS and what not the messages often "breakout" of their table and mess up the rest of my page.
So far I've tried the following:
I've got a little php function to strip script tags:
function stripHTML($html) {
$dom = new DOMDocument();
$dom->loadHTML($html);
$script = $dom->getElementsByTagName('script');
$remove = [];
foreach($script as $item) {
$remove[] = $item;
}
foreach ($remove as $item) {
$item->parentNode->removeChild($item);
}
$html = $dom->saveHTML();
return $html;
}
However, that is still obviously not doing the trick.
Can I wrap them in an iframe somehow maybe?