找到Html的哪个部分对PHP无效 [英] Find what part of Html is invalid with PHP

查看:78
本文介绍了找到Html的哪个部分对PHP无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试了几种方法来查明html字符串的哪一部分是无效的

I tried several methods to find out what part of a html string is invalid

$dom->loadHTML($badHtml);
$tidy->cleanRepair();
simplexml_load_string($badHtml);

无法清楚说明html的哪些部分无效。可能和额外的配置选项之一可以修复。任何想法?

None is clear regarding what part of the html is invalid. Maybe and extra config option for one of the can fix that. Any ideas ?

我需要这个来手动修复用户输入的html。我不想在自动化过程中进行转发。

I need this to manually fix html input from users. I don't want to relay on automated processes.

推荐答案

我会尝试将有问题的HTML加载到DOM Document中你已经在做),然后使用simplexml来修复问题。您应该可以运行快速比较来查看错误的位置。

I'd try loading the offending HTML into a DOM Document (as you are already doing) and then using simplexml to fix things. You should be able to run a quick diff to see where the errors are.

error_reporting(0);

$badHTML = '<p>Some <em><strong>badly</em> nested</stong> tags</p>';

$doc = new DOMDocument();
$doc->encoding = 'UTF-8';

$doc->loadHTML($badHTML);

$goodHTML = simplexml_import_dom($doc)->asXML();

这篇关于找到Html的哪个部分对PHP无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆