简体   繁体   English

如何找到未封闭的 html 标签或将奇怪的样式作为结果包含在一个元素中?

[英]How to find unclosed html tags or make the weird styling as a result contained in one element?

I have a tinyMCE editor that allows HTML.我有一个允许 HTML 的 tinyMCE 编辑器。

Sometimes a user pastes a table from a website or some other content that is not copied in its entirety, resulting in broken html.有时,用户从网站粘贴表格或其他未完整复制的内容,导致 html 损坏。

I display this content on a page which breaks sometimes due to this.我在有时会因此中断的页面上显示此内容。 Example image:示例图片:

在此处输入图像描述

What is the best way to fix this?解决此问题的最佳方法是什么? Is there a way to isolate this html somehow so the content of this element does not affect the rest of the page?有没有办法以某种方式隔离这个 html,所以这个元素的内容不会影响页面的其余部分? Or is there a function to automatically close all tags?还是有自动关闭所有标签的功能?

I just simply display the content like this:我只是简单地显示这样的内容:

<div class="editwindow">
    <h4 class="mt-0 m-b-30 header-title bigheader">'.$gettopcatcontent['title'].'</h4>
    <div class="content_tekst">'.$gettopcatcontent['content'].'</div>
    '.$versiondate.'
</div>

You can possibly use DOMDocument::loadHTML .您可以使用DOMDocument::loadHTML It will produce warnings for malformed HTML.它将为格式错误的 HTML 生成警告。

Set libxml_use_internal_errors to true and then use libxml_get_errors to handle the warnings.libxml_use_internal_errors设置为true ,然后使用libxml_get_errors处理警告。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM