title: HTML simple parser How to skip a tr inside a td in For each loop
body: <p>I have a html content like this... </p>
  
  <pre><code>$html = &lt;&lt;&lt;EOF
  &lt;table  id="specialTbl"&gt;
     &lt;tbody&gt;
        &lt;tr&gt;
           &lt;td&gt; row-1-td-1&lt;/td&gt;
           &lt;td&gt; row-1-td-2&lt;/td&gt;
           &lt;td&gt; row-1-td-3&lt;/td&gt;
           &lt;td&gt;
              &lt;table class="runsOn"&gt;  // Problem starts here
                 &lt;tbody&gt;
                    &lt;tr&gt;
                      &lt;td&gt;row-1-td-4-Child-1&lt;/td&gt; 
                      &lt;td&gt;row-1-td-4-Child-2&lt;/td&gt;               
                    &lt;/tr&gt;               
                 &lt;/tbody&gt;
              &lt;/table&gt;
           &lt;/td&gt;
           &lt;td&gt; row-1-td-5&lt;/td&gt;
           &lt;td&gt; row-1-td-6&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
           &lt;td&gt; row-2-td-1&lt;/td&gt;
           &lt;td&gt; row-2-td-2&lt;/td&gt;
           &lt;td&gt; row-2-td-3&lt;/td&gt;
           &lt;td&gt;
              &lt;table class="runsOn"&gt;
                 &lt;tbody&gt;
                    &lt;tr&gt;
                      &lt;td&gt;row-2-td-4-Child-1&lt;/td&gt;
                      &lt;td&gt;row-2-td-4-Child-2&lt;/td&gt;               
                    &lt;/tr&gt;               
                 &lt;/tbody&gt;
              &lt;/table&gt;
           &lt;/td&gt;
           &lt;td&gt; row-2-td-5&lt;/td&gt;
           &lt;td&gt; row-2-td-6&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
           &lt;td&gt; row-3-td-1&lt;/td&gt;
           &lt;td&gt; row-3-td-2&lt;/td&gt;
           &lt;td&gt; row-3-td-3&lt;/td&gt;
           &lt;td&gt;
              &lt;table class="runsOn"&gt;
                 &lt;tbody&gt;
                    &lt;tr&gt;
                      &lt;td&gt;row-3-td-4-Child-1&lt;/td&gt;
                      &lt;td&gt;row-3-td-4-Child-2&lt;/td&gt;               
                    &lt;/tr&gt;               
                 &lt;/tbody&gt;
              &lt;/table&gt;
           &lt;/td&gt;
           &lt;td&gt; row-3-td-5&lt;/td&gt;
           &lt;td&gt; row-3-td-6&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
           &lt;td&gt; row-4-td-1&lt;/td&gt;
           &lt;td&gt; row-4-td-2&lt;/td&gt;
           &lt;td&gt; row-4-td-3&lt;/td&gt;
           &lt;td&gt;
              &lt;table class="runsOn"&gt;
                 &lt;tbody&gt;
                    &lt;tr&gt;
                      &lt;td&gt;row-4-td-4-Child-1&lt;/td&gt;
                      &lt;td&gt;row-4-td-4-Child-2&lt;/td&gt;               
                    &lt;/tr&gt;               
                 &lt;/tbody&gt;
              &lt;/table&gt;
           &lt;/td&gt;
           &lt;td&gt; row-4-td-5&lt;/td&gt;
           &lt;td&gt; row-4-td-6&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
           &lt;td&gt; row-5-td-1&lt;/td&gt;
           &lt;td&gt; row-5-td-2&lt;/td&gt;
           &lt;td&gt; row-5-td-3&lt;/td&gt;
           &lt;td&gt;
              &lt;table class="runsOn"&gt;
                 &lt;tbody&gt;
                    &lt;tr&gt;
                      &lt;td&gt;row-5-td-4-Child-1&lt;/td&gt;
                      &lt;td&gt;row-5-td-4-Child-2&lt;/td&gt;               
                    &lt;/tr&gt;               
                 &lt;/tbody&gt;
              &lt;/table&gt;
           &lt;/td&gt;
           &lt;td&gt; row-5-td-5&lt;/td&gt;
           &lt;td&gt; row-5-td-6&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
           &lt;td&gt; row-6-td-1&lt;/td&gt;
           &lt;td&gt; row-6-td-2&lt;/td&gt;
           &lt;td&gt; row-6-td-3&lt;/td&gt;
           &lt;td&gt;
              &lt;table class="runsOn"&gt;
                 &lt;tbody&gt;
                    &lt;tr&gt;
                      &lt;td&gt;row-6-td-4-Child-1&lt;/td&gt;
                      &lt;td&gt;row-6-td-4-Child-2&lt;/td&gt;               
                    &lt;/tr&gt;               
                 &lt;/tbody&gt;
              &lt;/table&gt;
           &lt;/td&gt;
           &lt;td&gt; row-6-td-5&lt;/td&gt;
           &lt;td&gt; row-6-td-6&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
           &lt;td&gt; row-7-td-1&lt;/td&gt;
           &lt;td&gt; row-7-td-2&lt;/td&gt;
           &lt;td&gt; row-7-td-3&lt;/td&gt;
           &lt;td&gt;
              &lt;table class="runsOn"&gt;
                 &lt;tbody&gt;
                    &lt;tr&gt;
                      &lt;td&gt;row-7-td-4-Child-1&lt;/td&gt;
                      &lt;td&gt;row-7-td-4-Child-2&lt;/td&gt;               
                    &lt;/tr&gt;               
                 &lt;/tbody&gt;
              &lt;/table&gt;
           &lt;/td&gt;
           &lt;td&gt; row-7-td-5&lt;/td&gt;
           &lt;td&gt; row-7-td-6&lt;/td&gt;
        &lt;/tr&gt;  
     &lt;/tbody&gt;
  &lt;/table&gt;
  EOF;
  
  
  
  $html= str_get_html($html);
  $table =$html-&gt;find('table#specialTbl',0) ; 
  $response["response_code"] = 200;
  $response["rows"]   = array();
  foreach($table-&gt;find('tr') as $key=&gt;$value) {
   $post["td1"]= trim(strip_tags($value-&gt;find('td',0)-&gt;plaintext));
   $post["td2"]= trim(strip_tags($value-&gt;find('td',1)-&gt;plaintext));
   $post["td3"]= trim(strip_tags($value-&gt;find('td',2)-&gt;plaintext));
   $post["td4"]= trim(strip_tags($value-&gt;find('td',3)-&gt;plaintext)); 
   $post["td5"]= trim(strip_tags($value-&gt;find('td',4)-&gt;plaintext));
   $post["td6"]= trim(strip_tags($value-&gt;find('td',5)-&gt;plaintext)); 
    array_push($response["rows"], $post);  
  }
  $json = json_encode($response);
  echo $json_content;
  </code></pre>
  
  <p>And Json Response is </p>
  
  <pre><code>{
  "response_code":200,
  "rows":[
  {
  "td1":"row-1-td-1",
  "td2":"row-1-td-2",
  "td3":"row-1-td-3",
  "td4":"row-1-td-4-Child-1 row-1-td-4-Child-2",
  "td5":"row-1-td-4-Child-1",
  "td6":"row-1-td-4-Child-2"
  },
  {
  "td1":"row-1-td-4-Child-1",
  "td2":"row-1-td-4-Child-2",
  "td3":"",
  "td4":"",
  "td5":"",
  "td6":""
  },
  {
  "td1":"row-2-td-1",
  "td2":"row-2-td-2",
  "td3":"row-2-td-3",
  "td4":"row-2-td-4-Child-1 row-2-td-4-Child-2",
  "td5":"row-2-td-4-Child-1",
  "td6":"row-2-td-4-Child-2"
  },
  {
  "td1":"row-2-td-4-Child-1",
  "td2":"row-2-td-4-Child-2",
  "td3":"",
  "td4":"",
  "td5":"",
  "td6":""
  },
  {
  "td1":"row-3-td-1",
  "td2":"row-3-td-2",
  "td3":"row-3-td-3",
  "td4":"row-3-td-4-Child-1 row-3-td-4-Child-2",
  "td5":"row-3-td-4-Child-1",
  "td6":"row-3-td-4-Child-2"
  },
  {
  "td1":"row-3-td-4-Child-1",
  "td2":"row-3-td-4-Child-2",
  "td3":"",
  "td4":"",
  "td5":"",
  "td6":""
  },
  {
  "td1":"row-4-td-1",
  "td2":"row-4-td-2",
  "td3":"row-4-td-3",
  "td4":"row-4-td-4-Child-1 row-4-td-4-Child-2",
  "td5":"row-4-td-4-Child-1",
  "td6":"row-4-td-4-Child-2"
  },
  {
  "td1":"row-4-td-4-Child-1",
  "td2":"row-4-td-4-Child-2",
  "td3":"",
  "td4":"",
  "td5":"",
  "td6":""
  },
  {
  "td1":"row-5-td-1",
  "td2":"row-5-td-2",
  "td3":"row-5-td-3",
  "td4":"row-5-td-4-Child-1 row-5-td-4-Child-2",
  "td5":"row-5-td-4-Child-1",
  "td6":"row-5-td-4-Child-2"
  },
  {
  "td1":"row-5-td-4-Child-1",
  "td2":"row-5-td-4-Child-2",
  "td3":"",
  "td4":"",
  "td5":"",
  "td6":""
  },
  {
  "td1":"row-6-td-1",
  "td2":"row-6-td-2",
  "td3":"row-6-td-3",
  "td4":"row-6-td-4-Child-1 row-6-td-4-Child-2",
  "td5":"row-6-td-4-Child-1",
  "td6":"row-6-td-4-Child-2"
  },
  {
  "td1":"row-6-td-4-Child-1",
  "td2":"row-6-td-4-Child-2",
  "td3":"",
  "td4":"",
  "td5":"",
  "td6":""
  },
  {
  "td1":"row-7-td-1",
  "td2":"row-7-td-2",
  "td3":"row-7-td-3",
  "td4":"row-7-td-4-Child-1 row-7-td-4-Child-2",
  "td5":"row-7-td-4-Child-1",
  "td6":"row-7-td-4-Child-2"
  },
  {
  "td1":"row-7-td-4-Child-1",
  "td2":"row-7-td-4-Child-2",
  "td3":"",
  "td4":"",
  "td5":"",
  "td6":""
  }
  ]
  }
  </code></pre>
  
  <p>Problem is with <code>foreach</code>. How can i skip the <code>tr</code> inside a <code>td</code>. I have 7 rows in table with id "specialTbl". But <code>for each</code> returns 14 rows in json as it loops through table called runsOn.</p>
  
  <p>How can i avoid looping through table inside td(4th)</p>