Home > Backend Development > PHP Tutorial > How to solve the infinite loop in simple_html_dom execution?

How to solve the infinite loop in simple_html_dom execution?

WBOY
Release: 2016-07-06 13:51:39
Original
1221 people have browsed it

<code>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();
</code>
Copy after login
Copy after login

After this code is executed, infinite dump data comes out of the page, like an infinite loop. How to solve it? The a.list-group-item element must exist. . .

Reply content:

<code>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();
</code>
Copy after login
Copy after login

After this code is executed, infinite dump data comes out of the page, like an infinite loop. How to solve it? The a.list-group-item element must exist. . .

If you have used JavaScript, you should know that DOM is actually a tree, that is, DOM Tree. Each DOM node (node) will contain its direct parent node (parent node) and the serial number of the node to facilitate positioning and traversal rendering. Page, please think about it. If the nesting level is a little deeper, your var_dump will definitely not be able to output because the level is too deep (it usually shows a timeout when xdebug is not installed). After installing xdebug, please see: https://xdebug. org/docs/all_settings#var_display_max_depth will generally output a nesting depth of up to 3 levels, so I suggest not to use var_dump to debug simple_html_dom or its simple_html_dom_node objects. You can install xdebug for breakpoint debugging and play with high-end ones. How to do it specifically? Debugging is beyond the scope of this answer. Please Baidu "xdebug breakpoint debugging" by yourself.

There is a lot of content, so comments are not allowed, only answers can be posted...

The output data is relatively large because you dumped a few objects but did not arrive

Unlimited dump data level

<code>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) "<!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="UTF-8"/> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="csrf-param" content="_csrf">     <meta name="csrf-token" content="Lld4a0wtQW9gBz46Hlw0VxcxEjwYRytCQyVBPzxvKR1tJEkBOl4WDQ=="> <title>搴旂敤涓讳綋 - Yii 2.0 鏉冨▉鎸囧崡 - 鏂囨。 - Yii Framework 涓枃绀惧尯</title> <meta name="keywords" content="Yii Framewok, 鏉冨▉鎸囧崡"> <meta name="description" content="Yi"...
      protected $char =>
      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) {
        ...
      }
    }
  }
}</code>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template