h2 的 next 是 h3,h3没有child

解决方案 »

  1.   

    看这样式,应该是想要获取所有的ul吧?$ul = $doc->getElementsByTagName('*');
    这样是获取所有的元素的
    改成$ul = $doc->getElementsByTagName('ul');
    这样就会值获取页面的ul了。。这样的话,下面的循环操作就没有问题了。
      

  2.   

    谢谢两位回答。问题在stackoverflow上解决了。这个是elements之间空格的问题,空格也是视为一个node的,所以previousSibling是没问题,但用nextSibling时只取到空格的node.详情请看我在stackoverflow上的问题
    http://stackoverflow.com/questions/20851106/nextsibling-doesnt-work-when-working-with-php-domdocument-solved