Search code examples
phpdomhtml-parsingsimple-html-dom

PHP Simple HTML DOM Parser how to get Third table using find method


I have HTML code like following structure.

How can I fetch the 3rd table's content from this HTML code using PHP Simple HTML DOM find method?

<table width="100%" cellspacing="0" cellpadding="0" border="0">
  <tbody>
   <tr>
     <td>
       <table width="100%" cellspacing="0" cellpadding="0" border="0">
        <tbody>
          <tr>
           <td>
              <table width="100%" cellspacing="0" cellpadding="0" border="0">
              .......
              </table>

          </td>
         <tr>
        ..........
     <td>
  <tr>

</tbody>
</table>

Solution

  • To get third table pass second argument(index start from 0) in find method.

      $html = file_get_html(<your_file_url/html_code>);    
      $html->find("table", 2);