title: PHP Dom parse table to array
body: <p>I have table structure:</p>
  
  <pre><code>&lt;table class="c_order u_list"&gt;
      &lt;thead&gt;
          &lt;tr&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
              &lt;tr&gt;
              &lt;td&gt;
                  11.04.2017&lt;br/&gt;
                  18:20            &lt;/td&gt;
              &lt;td&gt;&lt;a target="_blank" href="/personal/order/detail/457/"&gt;A-457&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;+7 (917) 119-11-42&lt;/td&gt;
              &lt;td&gt;1685.20&lt;/td&gt;
              &lt;td&gt;
                  &lt;a target="_blank" href="/resn/i/zda_2_1/"&gt;УШКА&lt;/a&gt;&lt;br/&gt;с. холмский, ул. Фрунзе, д. 11&lt;br/&gt;3477740087            &lt;/td&gt;
              &lt;td&gt;Принят&lt;/td&gt;
          &lt;/tr&gt;
                  &lt;tr&gt;
              &lt;td&gt;
                  11.04.2017&lt;br/&gt;
                  16:47            &lt;/td&gt;
              &lt;td&gt;&lt;a target="_blank" href="/personal/order/detail/47565/"&gt;A-47565&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;+7 (909) 556-77-99&lt;/td&gt;
              &lt;td&gt;2574.80&lt;/td&gt;
              &lt;td&gt;
                  &lt;a target="_blank" href="/kir/a/an_10/"&gt;ООО &amp;quot;План&amp;quot;&lt;/a&gt;&lt;br/&gt;г. Омск, ул. 10-летия Победы, д. 3;&lt;br/&gt;8845701069            &lt;/td&gt;
              &lt;td&gt;Доставлен&lt;/td&gt;
          &lt;/tr&gt;
  
              &lt;/tbody&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>I am trying to get this to an array with my PHP code:</p>
  
  <pre><code>$page = curl_exec ($ch);
  curl_close ($ch);
  $dom = new DOMDocument();
  libxml_use_internal_errors(true);
  $dom-&gt;loadHTML($page);
  libxml_clear_errors();
  $xpath = new DOMXpath($dom);
  $data = array();
  // get all table rows and rows which are not headers
  $table_rows = $xpath-&gt;query('//tr');
  foreach($table_rows as $row =&gt; $tr) {
      foreach($tr-&gt;childNodes as $td) {
          echo $td-&gt;nodeValue;
          $data[$row][] = preg_replace('~[\r\n]+~', '', trim($td-&gt;nodeValue));
      }
      $data[$row] = array_values(array_filter($data[$row]));
  }
  print_r($data);
  </code></pre>
  
  <p>But I get wrong result (without a href tags) in array, but I need to get something like that including all tags in td elements:</p>
  
  <pre><code>Array
  (
      [0] =&gt; Array
      (
          [0] =&gt; 11.04.2017 18:20
          [1] =&gt; &lt;a target="_blank" href="/personal/order/detail/457/"&gt;A-457&lt;/a&gt;
          [2] =&gt; +7 (917) 119-11-42
          [3] =&gt; 1685.20
          [4] =&gt; &lt;a target="_blank" href="/resn/i/zda_2_1/"&gt;УШКА&lt;/a&gt;&lt;br/&gt;с. холмский, ул. Фрунзе, д. 11&lt;br/&gt;3477740087
          [5] =&gt; Принят
      )
  
      [1] =&gt; Array
      (
          [0] =&gt; 11.04.2017 16:47
          [1] =&gt; &lt;a target="_blank" href="/personal/order/detail/47565/"&gt;A-47565&lt;/a&gt;
          [2] =&gt; +7 (909) 556-77-99
          [3] =&gt; 2574.80
          [4] =&gt; &lt;a target="_blank" href="/kir/a/an_10/"&gt;ООО &amp;quot;План&amp;quot;&lt;/a&gt;&lt;br/&gt;г. Омск, ул. 10-летия Победы, д. 3;&lt;br/&gt;8845701069
          [5] =&gt; Доставлен
      )
  </code></pre>
  
  <p>And how to give name to arrays key index? So get not <code>[0]</code> but <code>['time']</code>.</p>