欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

simple_html_dom执行出现死循环如何解决?

程序员文章站 2022-05-04 21:21:01
...
include('simple_html_dom/simple_html_dom.php');
$list_html = new simple_html_dom();
$list_html->load_file('http://www.yiichina.com/doc/guide/2.0/structure-applications');
var_dump($list_html->find('a.list-group-item',0));exit();

这段代码执行之后在页面中无限dump数据出来,就像死循环一样如何解决?a.list-group-item元素是肯定存在的。。。

回复内容:

include('simple_html_dom/simple_html_dom.php');
$list_html = new simple_html_dom();
$list_html->load_file('http://www.yiichina.com/doc/guide/2.0/structure-applications');
var_dump($list_html->find('a.list-group-item',0));exit();

这段代码执行之后在页面中无限dump数据出来,就像死循环一样如何解决?a.list-group-item元素是肯定存在的。。。

用过javascript应该知道,这样dom其实是一棵树,即DOM Tree,每一个DOM节点(node)都会包含其直接父节点(parent node)和节点的序列号方便进行定位和遍历渲染出页面,请想想,嵌套层次如果稍微深一点的话,你var_dump肯定会因为层次太深而无法输出(没有安装xdebug时一般表现为超时),安装xdebug之后,请见:https://xdebug.org/docs/all_settings#var_display_max_depth,一般会输出最多3层的嵌套深度,所以我建议不要使用var_dump去调试simple_html_dom或其simple_html_dom_node的对象,可以安装xdebug进行断点调试,玩点高端的哈,具体怎么调试已经超出本回答范围,请自行百度“xdebug断点调试”。

内容比较多, 评论不让发, 只能发回答了...

输出的数据比较多, 是因为你dump了几个对象 但没到

无限dump数据的程度

class simple_html_dom_node#147 (9) {
  public $nodetype =>
  int(1)
  public $tag =>
  string(1) "a"
  public $attr =>
  array(4) {
    'class' =>
    string(15) "list-group-item"
    'href' =>
    string(5) "#w0-1"
    'data-toggle' =>
    string(8) "collapse"
    'data-parent' =>
    string(3) "#w0"
  }
  public $children =>
  array(1) {
    [0] =>
    class simple_html_dom_node#149 (9) {
      public $nodetype =>
      int(1)
      public $tag =>
      string(1) "b"
      public $attr =>
      array(1) {
        ...
      }
      public $children =>
      array(0) {
        ...
      }
      public $nodes =>
      array(0) {
        ...
      }
      public $parent =>
              ...

      public $_ =>
      array(5) {
        ...
      }
      public $tag_start =>
      int(3100)
      private $dom =>
      class simple_html_dom#3 (23) {
        ...
      }
    }
  }
  public $nodes =>
  array(2) {
    [0] =>
    class simple_html_dom_node#148 (9) {
      public $nodetype =>
      int(3)
      public $tag =>
      string(4) "text"
      public $attr =>
      array(0) {
        ...
      }
      public $children =>
      array(0) {
        ...
      }
      public $nodes =>
      array(0) {
        ...
      }
      public $parent =>
              ...

      public $_ =>
      array(1) {
        ...
      }
      public $tag_start =>
      int(0)
      private $dom =>
      class simple_html_dom#3 (23) {
        ...
      }
    }
    [1] =>
    class simple_html_dom_node#149 (9) {
      public $nodetype =>
      int(1)
      public $tag =>
      string(1) "b"
      public $attr =>
      array(1) {
        ...
      }
      public $children =>
      array(0) {
        ...
      }
      public $nodes =>
      array(0) {
        ...
      }
      public $parent =>
              ...

      public $_ =>
      array(5) {
        ...
      }
      public $tag_start =>
      int(3100)
      private $dom =>
      class simple_html_dom#3 (23) {
        ...
      }
    }
  }
  public $parent =>
  class simple_html_dom_node#146 (9) {
    public $nodetype =>
    int(1)
    public $tag =>
    string(3) "div"
    public $attr =>
    array(2) {
      'id' =>
      string(2) "w0"
      'class' =>
      string(10) "list-group"
    }
    public $children =>
    array(32) {
      [0] =>
              ...

      [1] =>
      class simple_html_dom_node#150 (9) {
        ...
      }
      [2] =>
      class simple_html_dom_node#157 (9) {
        ...
      }
      [3] =>
      class simple_html_dom_node#160 (9) {
        ...
      }
      [4] =>
      class simple_html_dom_node#182 (9) {
        ...
      }
      [5] =>
      class simple_html_dom_node#185 (9) {
        ...
      }
      [6] =>
      class simple_html_dom_node#222 (9) {
        ...
      }
      [7] =>
      class simple_html_dom_node#225 (9) {
        ...
      }
      [8] =>
      class simple_html_dom_node#250 (9) {
        ...
      }
      [9] =>
      class simple_html_dom_node#253 (9) {
        ...
      }
      [10] =>
      class simple_html_dom_node#281 (9) {
        ...
      }
      [11] =>
      class simple_html_dom_node#284 (9) {
        ...
      }
      [12] =>
      class simple_html_dom_node#309 (9) {
        ...
      }
      [13] =>
      class simple_html_dom_node#312 (9) {
        ...
      }
      [14] =>
      class simple_html_dom_node#328 (9) {
        ...
      }
      [15] =>
      class simple_html_dom_node#331 (9) {
        ...
      }
      [16] =>
      class simple_html_dom_node#353 (9) {
        ...
      }
      [17] =>
      class simple_html_dom_node#356 (9) {
        ...
      }
      [18] =>
      class simple_html_dom_node#372 (9) {
        ...
      }
      [19] =>
      class simple_html_dom_node#375 (9) {
        ...
      }
      [20] =>
      class simple_html_dom_node#391 (9) {
        ...
      }
      [21] =>
      class simple_html_dom_node#394 (9) {
        ...
      }
      [22] =>
      class simple_html_dom_node#422 (9) {
        ...
      }
      [23] =>
      class simple_html_dom_node#425 (9) {
        ...
      }
      [24] =>
      class simple_html_dom_node#435 (9) {
        ...
      }
      [25] =>
      class simple_html_dom_node#438 (9) {
        ...
      }
      [26] =>
      class simple_html_dom_node#457 (9) {
        ...
      }
      [27] =>
      class simple_html_dom_node#460 (9) {
        ...
      }
      [28] =>
      class simple_html_dom_node#491 (9) {
        ...
      }
      [29] =>
      class simple_html_dom_node#494 (9) {
        ...
      }
      [30] =>
      class simple_html_dom_node#501 (9) {
        ...
      }
      [31] =>
      class simple_html_dom_node#504 (9) {
        ...
      }
    }
    public $nodes =>
    array(47) {
      [0] =>
              ...

      [1] =>
      class simple_html_dom_node#150 (9) {
        ...
      }
      [2] =>
      class simple_html_dom_node#156 (9) {
        ...
      }
      [3] =>
      class simple_html_dom_node#157 (9) {
        ...
      }
      [4] =>
      class simple_html_dom_node#160 (9) {
        ...
      }
      [5] =>
      class simple_html_dom_node#181 (9) {
        ...
      }
      [6] =>
      class simple_html_dom_node#182 (9) {
        ...
      }
      [7] =>
      class simple_html_dom_node#185 (9) {
        ...
      }
      [8] =>
      class simple_html_dom_node#221 (9) {
        ...
      }
      [9] =>
      class simple_html_dom_node#222 (9) {
        ...
      }
      [10] =>
      class simple_html_dom_node#225 (9) {
        ...
      }
      [11] =>
      class simple_html_dom_node#249 (9) {
        ...
      }
      [12] =>
      class simple_html_dom_node#250 (9) {
        ...
      }
      [13] =>
      class simple_html_dom_node#253 (9) {
        ...
      }
      [14] =>
      class simple_html_dom_node#280 (9) {
        ...
      }
      [15] =>
      class simple_html_dom_node#281 (9) {
        ...
      }
      [16] =>
      class simple_html_dom_node#284 (9) {
        ...
      }
      [17] =>
      class simple_html_dom_node#308 (9) {
        ...
      }
      [18] =>
      class simple_html_dom_node#309 (9) {
        ...
      }
      [19] =>
      class simple_html_dom_node#312 (9) {
        ...
      }
      [20] =>
      class simple_html_dom_node#327 (9) {
        ...
      }
      [21] =>
      class simple_html_dom_node#328 (9) {
        ...
      }
      [22] =>
      class simple_html_dom_node#331 (9) {
        ...
      }
      [23] =>
      class simple_html_dom_node#352 (9) {
        ...
      }
      [24] =>
      class simple_html_dom_node#353 (9) {
        ...
      }
      [25] =>
      class simple_html_dom_node#356 (9) {
        ...
      }
      [26] =>
      class simple_html_dom_node#371 (9) {
        ...
      }
      [27] =>
      class simple_html_dom_node#372 (9) {
        ...
      }
      [28] =>
      class simple_html_dom_node#375 (9) {
        ...
      }
      [29] =>
      class simple_html_dom_node#390 (9) {
        ...
      }
      [30] =>
      class simple_html_dom_node#391 (9) {
        ...
      }
      [31] =>
      class simple_html_dom_node#394 (9) {
        ...
      }
      [32] =>
      class simple_html_dom_node#421 (9) {
        ...
      }
      [33] =>
      class simple_html_dom_node#422 (9) {
        ...
      }
      [34] =>
      class simple_html_dom_node#425 (9) {
        ...
      }
      [35] =>
      class simple_html_dom_node#434 (9) {
        ...
      }
      [36] =>
      class simple_html_dom_node#435 (9) {
        ...
      }
      [37] =>
      class simple_html_dom_node#438 (9) {
        ...
      }
      [38] =>
      class simple_html_dom_node#456 (9) {
        ...
      }
      [39] =>
      class simple_html_dom_node#457 (9) {
        ...
      }
      [40] =>
      class simple_html_dom_node#460 (9) {
        ...
      }
      [41] =>
      class simple_html_dom_node#490 (9) {
        ...
      }
      [42] =>
      class simple_html_dom_node#491 (9) {
        ...
      }
      [43] =>
      class simple_html_dom_node#494 (9) {
        ...
      }
      [44] =>
      class simple_html_dom_node#500 (9) {
        ...
      }
      [45] =>
      class simple_html_dom_node#501 (9) {
        ...
      }
      [46] =>
      class simple_html_dom_node#504 (9) {
        ...
      }
    }
    public $parent =>
    class simple_html_dom_node#144 (9) {
      public $nodetype =>
      int(1)
      public $tag =>
      string(3) "div"
      public $attr =>
      array(1) {
        ...
      }
      public $children =>
      array(1) {
        ...
      }
      public $nodes =>
      array(3) {
        ...
      }
      public $parent =>
      class simple_html_dom_node#142 (9) {
        ...
      }
      public $_ =>
      array(5) {
        ...
      }
      public $tag_start =>
      int(2936)
      private $dom =>
      class simple_html_dom#3 (23) {
        ...
      }
    }
    public $_ =>
    array(5) {
      [0] =>
      int(143)
      [2] =>
      array(2) {
        ...
      }
      [3] =>
      array(2) {
        ...
      }
      [7] =>
      string(0) ""
      [1] =>
      int(513)
    }
    public $tag_start =>
    int(2962)
    private $dom =>
    class simple_html_dom#3 (23) {
      public $root =>
      class simple_html_dom_node#2 (9) {
        ...
      }
      public $nodes =>
      array(1787) {
        ...
      }
      public $callback =>
      NULL
      public $lowercase =>
      bool(true)
      public $original_size =>
      int(48883)
      public $size =>
      int(46297)
      protected $pos =>
      int(46297)
      protected $doc =>
      string(46297) "  





搴旂敤涓讳綋 - Yii 2.0 鏉冨▉鎸囧崡 - 鏂囨。 - Yii Framework 涓枃绀惧尯


      NULL
      protected $cursor =>
      int(1787)
      protected $parent =>
      class simple_html_dom_node#2 (9) {
        ...
      }
      protected $noise =>
      array(90) {
        ...
      }
      protected $token_blank =>
      string(4) "     
"
      protected $token_equal =>
      string(4) " =/>"
      protected $token_slash =>
      string(6) " />
    "
      protected $token_attr =>
      string(2) " >"
      public $_charset =>
      string(5) "UTF-8"
      public $_target_charset =>
      string(5) "UTF-8"
      protected $default_br_text =>
      string(2) "
"
      public $default_span_text =>
      string(1) " "
      protected $self_closing_tags =>
      array(9) {
        ...
      }
      protected $block_tags =>
      array(6) {
        ...
      }
      protected $optional_closing_tags =>
      array(11) {
        ...
      }
    }
  }
  public $_ =>
  array(5) {
    [0] =>
    int(144)
    [2] =>
    array(4) {
      [0] =>
      int(0)
      [1] =>
      int(0)
      [2] =>
      int(0)
      [3] =>
      int(0)
    }
    [3] =>
    array(4) {
      [0] =>
      array(3) {
        ...
      }
      [1] =>
      array(3) {
        ...
      }
      [2] =>
      array(3) {
        ...
      }
      [3] =>
      array(3) {
        ...
      }
    }
    [7] =>
    string(0) ""
    [1] =>
    int(147)
  }
  public $tag_start =>
  int(2994)
  private $dom =>
  class simple_html_dom#3 (23) {
    public $root =>
    class simple_html_dom_node#2 (9) {
      public $nodetype =>
      int(5)
      public $tag =>
      string(4) "root"
      public $attr =>
      array(0) {
        ...
      }
      public $children =>
      array(2) {
        ...
      }
      public $nodes =>
      array(4) {
        ...
      }
      public $parent =>
      NULL
      public $_ =>
      array(2) {
        ...
      }
      public $tag_start =>
      int(0)
      private $dom =>
              ...

    }
    public $nodes =>
    array(1787) {
      [0] =>
      class simple_html_dom_node#2 (9) {
        ...
      }
      [1] =>
      class simple_html_dom_node#4 (9) {
        ...
      }
      [2] =>
      class simple_html_dom_node#5 (9) {
        ...
      }
      [3] =>
      class simple_html_dom_node#6 (9) {
        ...
      }
      [4] =>
      class simple_html_dom_node#7 (9) {
        ...
      }
      [5] =>
      class simple_html_dom_node#8 (9) {
        ...
      }
      [6] =>
      class simple_html_dom_node#9 (9) {
        ...
      }
      [7] =>
      class simple_html_dom_node#10 (9) {
        ...
      }
      [8] =>
      class simple_html_dom_node#11 (9) {
        ...
      }
      [9] =>
      class simple_html_dom_node#12 (9) {
        ...
      }
      [10] =>
      class simple_html_dom_node#13 (9) {
        ...
      }
      [11] =>
      class simple_html_dom_node#14 (9) {
        ...
      }
      [12] =>
      class simple_html_dom_node#15 (9) {
        ...
      }
      [13] =>
      class simple_html_dom_node#16 (9) {
        ...
      }
      [14] =>
      class simple_html_dom_node#17 (9) {
        ...
      }
      [15] =>
      class simple_html_dom_node#18 (9) {
        ...
      }
      [16] =>
      class simple_html_dom_node#19 (9) {
        ...
      }
      [17] =>
      class simple_html_dom_node#20 (9) {
        ...
      }
      [18] =>
      class simple_html_dom_node#21 (9) {
        ...
      }
      [19] =>
      class simple_html_dom_node#22 (9) {
        ...
      }
      [20] =>
      class simple_html_dom_node#23 (9) {
        ...
      }
      [21] =>
      class simple_html_dom_node#24 (9) {
        ...
      }
      [22] =>
      class simple_html_dom_node#25 (9) {
        ...
      }
      [23] =>
      class simple_html_dom_node#26 (9) {
        ...
      }
      [24] =>
      class simple_html_dom_node#27 (9) {
        ...
      }
      [25] =>
      class simple_html_dom_node#28 (9) {
        ...
      }
      [26] =>
      class simple_html_dom_node#29 (9) {
        ...
      }
      [27] =>
      class simple_html_dom_node#30 (9) {
        ...
      }
      [28] =>
      class simple_html_dom_node#31 (9) {
        ...
      }
      [29] =>
      class simple_html_dom_node#32 (9) {
        ...
      }
      [30] =>
      class simple_html_dom_node#33 (9) {
        ...
      }
      [31] =>
      class simple_html_dom_node#34 (9) {
        ...
      }
      [32] =>
      class simple_html_dom_node#35 (9) {
        ...
      }
      [33] =>
      class simple_html_dom_node#36 (9) {
        ...
      }
      [34] =>
      class simple_html_dom_node#37 (9) {
        ...
      }
      [35] =>
      class simple_html_dom_node#38 (9) {
        ...
      }
      [36] =>
      class simple_html_dom_node#39 (9) {
        ...
      }
      [37] =>
      class simple_html_dom_node#40 (9) {
        ...
      }
      [38] =>
      class simple_html_dom_node#41 (9) {
        ...
      }
      [39] =>
      class simple_html_dom_node#42 (9) {
        ...
      }
      [40] =>
      class simple_html_dom_node#43 (9) {
        ...
      }
      [41] =>
      class simple_html_dom_node#44 (9) {
        ...
      }
      [42] =>
      class simple_html_dom_node#45 (9) {
        ...
      }
      [43] =>
      class simple_html_dom_node#46 (9) {
        ...
      }
      [44] =>
      class simple_html_dom_node#47 (9) {
        ...
      }
      [45] =>
      class simple_html_dom_node#48 (9) {
        ...
      }
      [46] =>
      class simple_html_dom_node#49 (9) {
        ...
      }
      [47] =>
      class simple_html_dom_node#50 (9) {
        ...
      }
      [48] =>
      class simple_html_dom_node#51 (9) {
        ...
      }
      [49] =>
      class simple_html_dom_node#52 (9) {
        ...
      }
      [50] =>
      class simple_html_dom_node#53 (9) {
        ...
      }
      [51] =>
      class simple_html_dom_node#54 (9) {
        ...
      }
      [52] =>
      class simple_html_dom_node#55 (9) {
        ...
      }
      [53] =>
      class simple_html_dom_node#56 (9) {
        ...
      }
      [54] =>
      class simple_html_dom_node#57 (9) {
        ...
      }
      [55] =>
      class simple_html_dom_node#58 (9) {
        ...
      }
      [56] =>
      class simple_html_dom_node#59 (9) {
        ...
      }
      [57] =>
      class simple_html_dom_node#60 (9) {
        ...
      }
      [58] =>
      class simple_html_dom_node#61 (9) {
        ...
      }
      [59] =>
      class simple_html_dom_node#62 (9) {
        ...
      }
      [60] =>
      class simple_html_dom_node#63 (9) {
        ...
      }
      [61] =>
      class simple_html_dom_node#64 (9) {
        ...
      }
      [62] =>
      class simple_html_dom_node#65 (9) {
        ...
      }
      [63] =>
      class simple_html_dom_node#66 (9) {
        ...
      }
      [64] =>
      class simple_html_dom_node#67 (9) {
        ...
      }
      [65] =>
      class simple_html_dom_node#68 (9) {
        ...
      }
      [66] =>
      class simple_html_dom_node#69 (9) {
        ...
      }
      [67] =>
      class simple_html_dom_node#70 (9) {
        ...
      }
      [68] =>
      class simple_html_dom_node#71 (9) {
        ...
      }
      [69] =>
      class simple_html_dom_node#72 (9) {
        ...
      }
      [70] =>
      class simple_html_dom_node#73 (9) {
        ...
      }
      [71] =>
      class simple_html_dom_node#74 (9) {
        ...
      }
      [72] =>
      class simple_html_dom_node#75 (9) {
        ...
      }
      [73] =>
      class simple_html_dom_node#76 (9) {
        ...
      }
      [74] =>
      class simple_html_dom_node#77 (9) {
        ...
      }
      [75] =>
      class simple_html_dom_node#78 (9) {
        ...
      }
      [76] =>
      class simple_html_dom_node#79 (9) {
        ...
      }
      [77] =>
      class simple_html_dom_node#80 (9) {
        ...
      }
      [78] =>
      class simple_html_dom_node#81 (9) {
        ...
      }
      [79] =>
      class simple_html_dom_node#82 (9) {
        ...
      }
      [80] =>
      class simple_html_dom_node#83 (9) {
        ...
      }
      [81] =>
      class simple_html_dom_node#84 (9) {
        ...
      }
      [82] =>
      class simple_html_dom_node#85 (9) {
        ...
      }
      [83] =>
      class simple_html_dom_node#86 (9) {
        ...
      }
      [84] =>
      class simple_html_dom_node#87 (9) {
        ...
      }
      [85] =>
      class simple_html_dom_node#88 (9) {
        ...
      }
      [86] =>
      class simple_html_dom_node#89 (9) {
        ...
      }
      [87] =>
      class simple_html_dom_node#90 (9) {
        ...
      }
      [88] =>
      class simple_html_dom_node#91 (9) {
        ...
      }
      [89] =>
      class simple_html_dom_node#92 (9) {
        ...
      }
      [90] =>
      class simple_html_dom_node#93 (9) {
        ...
      }
      [91] =>
      class simple_html_dom_node#94 (9) {
        ...
      }
      [92] =>
      class simple_html_dom_node#95 (9) {
        ...
      }
      [93] =>
      class simple_html_dom_node#96 (9) {
        ...
      }
      [94] =>
      class simple_html_dom_node#97 (9) {
        ...
      }
      [95] =>
      class simple_html_dom_node#98 (9) {
        ...
      }
      [96] =>
      class simple_html_dom_node#99 (9) {
        ...
      }
      [97] =>
      class simple_html_dom_node#100 (9) {
        ...
      }
      [98] =>
      class simple_html_dom_node#101 (9) {
        ...
      }
      [99] =>
      class simple_html_dom_node#102 (9) {
        ...
      }
      [100] =>
      class simple_html_dom_node#103 (9) {
        ...
      }
      [101] =>
      class simple_html_dom_node#104 (9) {
        ...
      }
      [102] =>
      class simple_html_dom_node#105 (9) {
        ...
      }
      [103] =>
      class simple_html_dom_node#106 (9) {
        ...
      }
      [104] =>
      class simple_html_dom_node#107 (9) {
        ...
      }
      [105] =>
      class simple_html_dom_node#108 (9) {
        ...
      }
      [106] =>
      class simple_html_dom_node#109 (9) {
        ...
      }
      [107] =>
      class simple_html_dom_node#110 (9) {
        ...
      }
      [108] =>
     y(3) {
        ...
      }
      'th' =>
      array(1) {
        ...
      }
      'td' =>
      array(1) {
        ...
      }
      'li' =>
      array(1) {
        ...
      }
      'dt' =>
      array(2) {
        ...
      }
      'dd' =>
      array(2) {
        ...
      }
      'dl' =>
      array(2) {
        ...
      }
      'p' =>
      array(1) {
        ...
      }
      'nobr' =>
      array(1) {
        ...
      }
      'b' =>
      array(1) {
        ...
      }
      'option' =>
      array(1) {
        ...
      }
    }
  }
}