title: Regular expression html table extract using PHP function preg_match_all
body: <p>I want to extract table from html page which contains nested html table tags after that I want to extract <code>&lt;td&gt;</code> and <code>&lt;tr&gt;</code>of tables.</p>
  
  <p>I am using this. Its working fine for <code>&lt;b&gt;</code> and <code>&lt;/b&gt;</code></p>
  
  <pre><code>$file = file_get_contents($url);
  preg_match_all ("/&lt;b&gt;(.*)&lt;\/b&gt;/U", $file, $pat_array);
  print $pat_array[0][0]." &lt;br&gt; ".$pat_array[0][1]."\n";
  </code></pre>
  
  <p>Can anybody tell me regular expression for nested <code>&lt;table (some table properties)&gt;</code>  some data using <code>&lt;tr&gt;</code> and <code>&lt;td&gt; &lt;/table&gt;</code>. Please keep the href if present in the <code>&lt;tr&gt;</code> or <code>&lt;td&gt;</code> fields, and keep in mind the needed tables.</p>
  
  <p>Example:</p>
  
  <pre><code>$file = "&lt;html&gt; &lt;head&gt; &lt;title&gt; asdf &lt;/title&gt; &lt;/head&gt; &lt;body bgcolor = red &gt;  &lt;table border = 1&gt; &lt;table bgcolor = white&gt; (some tr and td data &gt; &lt;/table&gt; &lt;/table&gt;&lt;/body&gt; &lt;/body&gt; &lt;/html&gt;"
  
  preg_match_all ("regular expression for table tag", $file, $pat_array);
  print $pat_array[0][0]." &lt;br&gt; ".$pat_array[0][1]."\n";
  </code></pre>
  
  <p>Update 1 :</p>
  
  <p>When I tried below code it shows the error:</p>
  
  <blockquote>
    <p>Notice: Undefined offset: 0 in C:\xampp\htdocs\testphp\tabledata.php on line 27 </p>
  </blockquote>
  
  <p>Code:</p>
  
  <pre><code>$file = file_get_contents($url);
  $pat_array = Array();
  preg_match_all ("/&lt;tr&gt;(.*)&lt;\/tr&gt;/U", $file, $pat_array);
  print $pat_array[1][0];
  </code></pre>
  
  <p>Can anybody help me regarding this error also?</p>