Possible Array in PHP

MarthaJ Sayers
MarthaJ Sayers used Ask the Experts™
on
I have some data that I have extracted, stripped out unneeded characters
and I was wondering if somehow I could define the rest of it as an array.
I am using PHP v 5.6.25
The stripped out data consist of 5 rows and each row contains 7 cells.
My first thought was grab each <tr></tr> section, finding the position of first <td> and then it's corresponding ending </td> and looping thru each <td> cell.
I would save the position of the previous ending </td> so be starting point of next cycle.
But I was wondering if I could define the <td></td> cells as an array - would be a heck of alot easier to extract the data
Below is what a section looks like and it is the same thru out table.
Maybe use eplode function first to redefine as an array ??

<tr>
<td >blah<br>blah blah</td>
<td >229939</td>
<td >09/06/2019</td>
<td >23.00</td>
<td >0.00</td>
<td ><br></td>
<td >23.00</td>
<td >more info</td>
</tr>

Open in new window



Any thoughts would help. I can do it the long way but it would be nice to have a short cut...and more effective and efficient,
thank you...
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
I experiment with explode and that has worked very well.

Commented:
Just one comment - be wary of trying to extract data from HTML, especially from traditional HTML tables. If you don't control the content already, then any change in the HTML code (even whitespace) could end up breaking your code. HTML is intentionally not  very strict, so it's dangerous to try and use HTML structures as if they were reliable data structures.

You can help avoid this a little by using an HTML parser like simplehtmldom but if the owner of the content ever decides to just stop using traditional tables and switch to div-based tables, then that will also break your code. Whenever possible, you should try to see if you can get the data from an API instead of extracting it from HTML. An API is far more likely to stay reliable and give you very organized data that doesn't require you to manually parse it.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial