【问题标题】:DOMDocument loadHTML function failsDOMDocument loadHTML 函数失败
【发布时间】: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


【解决方案1】:

您检查了服务器上的 error_log 吗?

另外,尝试一下,看看会发生什么:

file_put_contents('output.txt', "failed: ". print_r($ex, true));

【讨论】:

  • 打印 $ex 没有按照您建议的方式工作。我会回到日志上。我正在使用远程 zend 服务器,所以我还不能检查它。
猜你喜欢
  • 2012-02-27
  • 2014-06-15
  • 2012-05-18
  • 2017-01-02
  • 2011-11-12
  • 2014-03-10
  • 1970-01-01
  • 1970-01-01
  • 2014-02-16
相关资源
最近更新 更多