【发布时间】:2014-04-01 17:01:50
【问题描述】:
我正在尝试将一些 html 加载到 DOMDocument 中,但我无法正确调试它。
这是原始的(未格式化的)HTML 字符串:
<html><head><title>Pagina 1</title>
<link rel='stylesheet' href='/css/SxCms.css' type='text/css'></head><body>
<div id='editorWrapper' style='postion: relative; z-index: 1; width:1600 height: 1131px;'>
<img id='editingImage' src='/img/briefingStartP-Stages2013-2014.pdf/briefingstartp-stages2013-2014_1395824936_1.jpg' /></div></body></html>
这就是我加载它的方式(简单明了):
try {
libxml_use_internal_errors(true);
$doc = new DOMDocument();
file_put_contents('output.txt', 'doc created');
if (!$doc->loadHTML($html)) {
file_put_contents('output.txt', "loadfails: ".libxml_get_errors());
libxml_clear_errors();
}
} catch (Exception $ex) {
file_put_contents('output.txt', "failed: $ex");
}
output.txt 中的最后一个输出是“doc created”。我应该看到一个异常吧?
任何帮助表示赞赏:)
编辑
使用 libxml_use_internal_errors(true) 没有帮助。我仍然在我的输出文件中创建了 doc。
【问题讨论】:
-
$html的内容是什么? -
对不起,这个变量保存了上一个块中的原始 html
-
您可能想签出this。
-
@passerby 我更新了我的问题。仍然在我的输出文件中创建了文档。
-
@RobbieVercammen 你有错误报告吗?您在 PHP 日志中看到任何错误吗?
标签: php html domdocument