Jump to content

Read Data from HTML Table with PHP


lihman

Recommended Posts

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?

Link to comment
Share on other sites

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.

 

 

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.