PHP Classes

What is the best PHP html table parser class?: Does a class exist that can process an HTML table?

Recommend this page to a friend!
  All requests RSS feed  >  What is the best PHP html table parse...  >  Request new recommendation  >  A request is featured when there is no good recommended package on the site when it is posted. Featured requests  >  No recommendations No recommendations  

What is the best PHP html table parser class?


Picture of Nyle Davis by Nyle Davis - 3 years ago (2021-01-23)

Does a class exist that can process an HTML table?

This request is clear and relevant.
This request is not clear or is not relevant.



I'm needing to process an HTML table and need to know, for time savings, if such an object already exits.

I have not been here on this site, for over 10 years and originally wrote up my issue at:

So here is what I'm looking for:

Quick Q: Does anyone know a PHP script or function that reads html table colums into an array? The tag "<tr>" would have to iterate the array! The hardest variants are in the columns of the first row, where column widths are defined vs other rows where they are not.

HTML Example:

<table align="center" border="0" cellpadding="0" cellspacing="0" width="100%"> <tr> <td width=200><b>12 Angels</b></td> <td width=80><a href=""><b>Link</b></a></td> <td width=100><b><a href="mailto:">EMail-Unlisted</a></b></td> <td width=150><b>(888)-233-1411</b></td> </tr>

<tr> <td><b>Active Angel Investors</b></td> <td><a href=""><b>Link</b></a></td> <td><b><a href="">EMail</a></b></td> <td><b>(703)-255-4930</b></td> </tr> </table>

Where each occurance of "<tr>" must increment the output array, reset the column counter to "0" and each occurance of "<td" must increment the column counter.

The columns with "width=" must process the same as the ones without "width". Hope that explains it.

If you know an object, preferably with REGEX, please respond with that resource.



Ask clarification

1 Recommendation

FluidXML: Manipulate XML documents using a fluent interface

This recommendation solves the problem.
This recommendation does not solve the problem.


Picture of Manuel Lemos by Manuel Lemos Reputation 23760 - 3 years ago (2021-01-27) Comment

Nowdays PHP comes with DOM document parsing which works well for parsing XML and HTML documents. It is a real document parser, so it does not use complex regular expressions. Regular expressions are complicated and error prone.

Using a DOM based parser will allow you to use XPATH, which is a sort of matching language that will allow you to specify the path of the elements of the table that you want to extract, so you only need to write a few lines of code to do what you need.

Look at the example code that is on this package page.

You may also want to study XPATH syntax to query the table elements that you need. Check the XPATH pages in Wikipedia or W3C site.

Recommend package