title: Using dom php to get data from table html
body: <p>i have this error:</p>
  
  <pre><code>Error Trying to get property of non-object
  </code></pre>
  
  <p>and the code is:</p>
  
  <pre><code> $dom-&gt;preserveWhiteSpace = false; 
  
      $tables = $dom-&gt;getElementsByTagName('table'); 
  
      $rows = $tables-&gt;item(0)-&gt;getElementsByTagName('tr'); 
  
     $i=0; 
     foreach ($rows as $row) 
      { 
          /*** get each column by tag name ***/ 
          $cols = $row-&gt;getElementsByTagName('td'); 
  
          $this-&gt;data['Table'][$i] = array(
                             'Attrb1' =&gt; $cols-&gt;item(0)-&gt;nodeValue,
                             'Attrib2' =&gt; $cols-&gt;item(1)-&gt;nodeValue
  
                                    );
       $i++;
  
      } 
           }
  
          return $this-&gt;toArray();
      }
  </code></pre>
  
  <p>The line that i have this error is :                                </p>
  
  <pre><code>'Attrib2' =&gt; $cols-&gt;item(1)-&gt;nodeValue
  </code></pre>
  
  <p>the html code is:</p>
  
  <pre><code>&lt;table border=1 align="center" cellpadding=5 width="95%"&gt;
                                              &lt;!doctype html public "-//w3c//dtd html 4.0//EN"&gt;
  &lt;html it&gt;
  &lt;head&gt;
  &lt;meta name="Generator" content="OLS"&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;td colspan=2 align="center"&gt;
  &lt;b&gt;
  &lt;i&gt;
  Attrib1
  &lt;/i&gt;
  &lt;/b&gt;
  &lt;/td&gt;
  &lt;td&gt;
  &lt;b&gt;
  &lt;i&gt;
  Attrib2
  &lt;/i&gt;
  &lt;/b&gt;
  &lt;/td&gt;
  &lt;td&gt;
  &lt;b&gt;
  &lt;i&gt;
  &lt;tr&gt;
  &lt;td&gt;
  A000211
  &lt;/td&gt;
  &lt;td nowrap&gt;
  Statistic
  &lt;/td&gt;
  &lt;/tr&gt;
  </code></pre>
  
  <p>but i don't know if the problem is in the foreach or all get data that i make is one big error or i process the html in a wrong way..so help me please..</p>