Avatar of MarthaJ Sayers
MarthaJ Sayers
 asked on

Possible Array in PHP

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 ??

<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>

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...

Avatar of undefined
Last Comment

8/22/2022 - Mon
MarthaJ Sayers

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question

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.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck