【问题标题】:Return cleaner Simple HTML DOM array返回更清洁的简单 HTML DOM 数组
【发布时间】:2013-07-01 17:31:37
【问题描述】:

我使用Simple HTML Dom从页面上的表格中返回一个数组,表格是这样的

<table width="414" cellspacing="4" cellpadding="0" border="0">
<tbody>
<tr>
<td width="170">Total :</td>
<td>58,262</td>
</tr>
... // there are about another 10 <tr> tags, and table closing tags after that.

但是当我运行命令print_r($es = $html-&gt;find('table[width=414]')); 时,我得到一个巨大的数组(与它的解析相反),下面的示例将我们带到第一个“Total:”行,接下来是下面大约 200 行。有什么想法可以让我得到更“消毒”的结果吗?

Array ( [0] => simple_html_dom_node Object ( [nodetype] => 1 [tag] => table [attr] => Array ( [cellpadding] => 0 [cellspacing] => 4 [border] => 0 [width] => 414 ) [children] => Array ( [0] => simple_html_dom_node Object ( [nodetype] => 1 [tag] => tr [attr] => Array ( ) [children] => Array ( [0] => simple_html_dom_node Object ( [nodetype] => 1 [tag] => td [attr] => Array ( [width] => 170 ) [children] => Array ( ) [nodes] => Array ( [0] => simple_html_dom_node Object ( [nodetype] => 3 [tag] => text [attr] => Array ( ) [children] => Array ( ) [nodes] => Array ( ) [parent] => simple_html_dom_node Object *RECURSION* [_] => Array ( [4] => Total : ) 

【问题讨论】:

    标签: php html-parsing simple-html-dom


    【解决方案1】:

    你只需要使用前置标签:

    <pre>
    
        <?php print_r($es = $html->find('table[width=414]'); ?>
    
    </pre>
    

    它的作用是根据 print_r 的结果为空格和换行生成正确的 HTML。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多