lihman Posted September 1, 2009 Share Posted September 1, 2009 I need to use PHP to read from an HTML table and assign specific columns/cells into arrays. Example of Table: <table width="100%" cellspacing="2" cellpadding="1"> <tr> <td class="box_header" width="50" align="center">Rank</td> <td class="box_header" width="150" align="center">Username</td> <td class="box_header" width="100" align="center">Gold</td> <td class="box_header" width="100" align="center">Army Size</td> <td class="box_header" width="75" align="center">Level</td> <td class="box_header" width="75" align="center">Race</td> </tr> <tr> <td class="box_content" colspan="6" align="center">Currently viewing page 851 of 4086</td> </tr> <tr> <td class="box_content" colspan="3"> <a href="userlist.dt?session=&mode=attack&page=850">Previous</a> </td> <td class="box_content" colspan="3" align="right"> <a href="userlist.dt?session=&mode=attack&page=852">Next</a> </td> </tr> <tr> <td class="box_content" align="center">42,501</td> <td class="box_content"><a href="/viewprofile.dt?session=&id=1045135">Helyanwe</a></td> <td class="box_content" align="center">413,694,847</td> <td class="box_content" align="center">109,695</td> <td class="box_content" align="center">55</td> <td class="box_content" align="center"><img src="/images/raceicons/2.gif" alt="Undead"></td> </tr> <tr> <td class="box_content" align="center">42,502</td> <td class="box_content"><a href="/viewprofile.dt?session=&id=1171592">white_knight2000</a></td> <td class="box_content" align="center">233,555,927</td> <td class="box_content" align="center">30,356</td> <td class="box_content" align="center">55</td> <td class="box_content" align="center"><img src="/images/raceicons/3.gif" alt="Goblins"></td> </tr> <tr> <td class="box_content" align="center">42,503</td> <td class="box_content"><a href="/viewprofile.dt?session=&id=1143368">BreKo2</a></td> <td class="box_content" align="center">19,753,118</td> <td class="box_content" align="center">62,698</td> <td class="box_content" align="center">55</td> <td class="box_content" align="center"><img src="/images/raceicons/1.gif" alt="Humans"></td> </tr> The thing is that the content in the cells keeps changing so I need to be able to use it as variables/arrays. for example: $row4[2] can display 413,694,847. (I went 4 rows down and 3 columns to the right) How can I make this work? Quote Link to comment Share on other sites More sharing options...
waynewex Posted September 1, 2009 Share Posted September 1, 2009 Hi. I'm a little confused about what you're wanting to achieve. Does another site implement this that you can link us to? Otherwise you're going to have to explain it a little more clearly. Quote Link to comment Share on other sites More sharing options...
lihman Posted September 1, 2009 Author Share Posted September 1, 2009 Ok, I'll make it a bit more clear. IF there's a table like this: <table> <tr> <td>Name</td> <td>Age</td> </tr> <tr> <td>Lihman</td> <td>25</td> </tr> <td>Waynewex</td> <td>25</td> </tr> </table> I need a php script that can read that and somehow assign variables to "Lihman" and "25". However, I cannot make any changes to the table. So I was thinking maybe $name[0] would equal "Lihman" and $name[1] would equal "Waynewex". I am using this with php/cURL and the table will keep changing so I can't just make it so that $name[0] will always equal "Lihman" which is why i need the script to read from the table. Quote Link to comment Share on other sites More sharing options...
waynewex Posted September 1, 2009 Share Posted September 1, 2009 Then what you need to read into/get help with is regular expressions. There's a regular expression help sub-forum on this forum. Quote Link to comment Share on other sites More sharing options...
lihman Posted September 1, 2009 Author Share Posted September 1, 2009 Can a mod please move this topic into that sub-forum? I'll be even more specific to what I need if that makes changes to the script: <table> <tr> <td>Name</td> <td>Age</td> </tr> <tr> <td><a href="1025.html">Lihman</a></td> <td>50</td> </tr> <td><a href="5245.html">Waynewex</a></td> <td>25</td> </tr> </table> I then need to make a php/cURL script that will change the $url to lihman.html or waynewex.html depending on the age. Example (not a real script): if { $age > 35; $url = "http://localhost/" . [WHATEVER COMES BETWEEN href=""]; } Therefore, $url would equal http://localhost/1025.html. Quote Link to comment Share on other sites More sharing options...
lihman Posted September 3, 2009 Author Share Posted September 3, 2009 Can someone please move this to regex? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.