【问题标题】:Parsing Malformed HTML with PHP Dom使用 PHP Dom 解析格式错误的 HTML
【发布时间】:2010-03-04 22:53:40
【问题描述】:

我有一位客户希望在他们的网站上显示他们的视频(由第三方提供)。该网站使用 swfobject 来显示视频,所以我认为最简单的方法是抓取它并稍微修改它,以便它可以在客户端的网站上运行。

使用 PHP DOMDocument 似乎是可行的方法,但不幸的是,提供的 HTML 格式不正确并导致心脏病发作。是否有可能让它忽略 HTML 中的错误,或者我可以这样做的替代方法?

【问题讨论】:

    标签: php html-parsing domdocument


    【解决方案1】:

    这就是PHP Tidy 的用途。对于example

    <?php
    ob_start();
    ?>
    <html>a html document</html>
    <?php
    $html = ob_get_clean();
    
    // Specify configuration
    $config = array(
               'indent'         => true,
               'output-xhtml'   => true,
               'wrap'           => 200);
    
    // Tidy
    $tidy = new tidy;
    $tidy->parseString($html, $config, 'utf8');
    $tidy->cleanRepair();
    
    // Output
    echo $tidy;
    ?>
    

    HTML Tidy Configuration Options

    【讨论】:

      【解决方案2】:

      如果你喜欢 jQuery,你可以使用“Simple HTML Dom Parser”。效果很好。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-10-13
        • 1970-01-01
        • 2018-02-23
        • 2011-05-18
        • 2015-04-29
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多