Retrieving HTML data from a table
Posted: Sun Mar 18, 2007 7:08 am
Hi guys,
I've had a read of regex but I find it hard to understand most of it.
Basically, what I would like to do is to have a code that looks through a html table and grabs the data, storing them in separate strings to be inserted into a mysql database. An example of the table is:
Notice that the bgcolor alternates between #ffffff and #202020, when one of the information above is not given, the entire <tr></tr> will not be displayed, and the colours still alternate. For example, if we were to take out the "degree" data in between Age and Country,
... the bgcolor still alternates!
I would like to be able to save all the info into their respective strings (Jacob Mcgrath to $name, Male to $gender, Ireland to $country, etc)
Thanks in advance
I've had a read of regex but I find it hard to understand most of it.
Basically, what I would like to do is to have a code that looks through a html table and grabs the data, storing them in separate strings to be inserted into a mysql database. An example of the table is:
Code: Select all
<table><tr bgcolor=#000000><td colspan=2>
<b>Personal Information</b></td></tr>
<tr bgcolor=#202020><td width=20%>Name:</td><td>Jacob McGrath</td></tr>
<tr bgcolor=#ffffff><td>Gender:</td><td>male</td></tr>
<tr bgcolor=#202020><td>E-mail:</td><td>myemail@yourdomain.com</td></tr>
<tr bgcolor=#ffffff><td>Country:</td><td>Ireland</td></tr>
<tr bgcolor=#202020><td>Age:</td><td>23</td></tr>
<tr bgcolor=#ffffff><td>Degree:</td><td>Bachelor of Engineering</td></tr>
<tr bgcolor=#202020><td>Company:</td><td>McGrath's Engineering</td></tr>
<tr bgcolor=#ffffff><td>Link:</td><td><a href="http://www.yourdomain.com/mcgrath">McGrath</a></td></tr>
<tr bgcolor=#202020><TD>TimeZone:</td><td>GMT +3.00</td></tr>
</table>Code: Select all
<table><tr bgcolor=#000000><td colspan=2>
<b>Personal Information</b></td></tr>
<tr bgcolor=#202020><td width=20%>Name:</td><td>Jacob McGrath</td></tr>
<tr bgcolor=#ffffff><td>Gender:</td><td>male</td></tr>
<tr bgcolor=#202020><td>E-mail:</td><td>myemail@yourdomain.com</td></tr>
<tr bgcolor=#ffffff><td>Country:</td><td>Ireland</td></tr>
<tr bgcolor=#202020><td>Age:</td><td>23</td></tr>
<tr bgcolor=#ffffff><td>Company:</td><td>McGrath's Engineering</td></tr>
<tr bgcolor=#202020><td>Link:</td><td><a href="http://www.yourdomain.com/mcgrath">McGrath</a></td></tr>
<tr bgcolor=#ffffff><TD>TimeZone:</td><td>GMT +3.00</td></tr>
</table>I would like to be able to save all the info into their respective strings (Jacob Mcgrath to $name, Male to $gender, Ireland to $country, etc)
Thanks in advance