2

如何使用获取simple_html_dom每个值aaa,,,,?谢谢。bbbcccddd

HTML结构:

<body>
  <div>
    <div>
      <div>
        <div>
          aaa
        </div>
        bbb
      </div>
      ccc
    </div>
    ddd
  </div>
</body>

<?php
require('simple_html_dom.php');
$html = str_get_html('<body><div><div><div><div>aaa</div>bbb</div>ccc</div>ddd</div></body>');
echo $html->find('div', 0)->innertext.'<hr />'; //need output aaa
echo $html->find('div', 1)->innertext.'<hr />'; //need output bbb
echo $html->find('div', 2)->innertext.'<hr />'; //need output ccc
echo $html->find('div', 3)->innertext.'<hr />'; //need output ddd
?>
4

1 回答 1

0

如果 intertext 不返回嵌套标签,那么这应该有效:

echo $html->find('body', 0)->find('div', 0)->find('div',0)->find('div',0)->find('div',0)->innertext.'<hr />'; // prints aaa
echo $html->find('body', 0)->find('div', 0)->find('div',0)->find('div',0)->->innertext.'<hr />'; // prints bbb
echo $html->find('body', 0)->find('div', 0)->find('div',0)->innertext.'<hr />'; // prints ccc
echo $html->find('body', 0)->find('div', 0)->innertext.'<hr />'; // prints ddd
于 2011-07-11T18:53:11.617 回答