title: How do you web scrape nested table using PHP?
body: <p><strong>Backstory</strong>
  First off, I have used PHP to read email and extract out the HTML attachment which later on I stored in a PHP variable. </p>
  
  <p>Now the problem I am facing is that I am trying to extract out information from the HTML in a nested table and hoping to convert to some sort of array so that I can store in SQL.</p>
  
  <p>May I know if there are solutions for this? As I have tried finding but to no avail.</p>
  
  <p><strong>Example</strong></p>
  
  <pre><code>&lt;html&gt;
      &lt;table&gt;
          &lt;tr&gt;
              &lt;td&gt;
                  &lt;table&gt;
                      &lt;tr&gt;
                          &lt;td&gt;&lt;/td&gt;
                          &lt;/td&gt;
                      &lt;/tr&gt;
                  &lt;/table&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
                  &lt;table&gt;
                      &lt;tr&gt;
                          &lt;td&gt;
                              &lt;p&gt;hi&lt;/p&gt;
                          &lt;/td&gt;
                      &lt;/tr&gt;
                  &lt;/table&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
      &lt;/table&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>I want to locate the nearest table tag where "hi" is located so that I can get all the information from that table</p>
  
  <p><strong>Stuff I have tried</strong></p>
  
  <p>I have tried using simple HTML DOM but I guess the HTML file that I tried scraping was too large that it causes memory issues.</p>
  
  <pre><code>include('./simple_html_dom.php');
  
  /* Parse the HTML, stored as a string in $woString */ &lt;br&gt;
  $html = str_get_html($worksOrder); 
  
  /* Locate the ultimate grandfather table id that wraps all his generation */&lt;br&gt;
  $messytables = $html-&gt;find('table');
  
  print_r($messytables);
  </code></pre>