Cory94bailly Posted August 18, 2010 Share Posted August 18, 2010 I know how much you guys hate people asking for help without any starting code but I'm not even sure how to start this.. I want a script to read this page and count all the admins and referees. If anyone is willing to help, here's a sample of the html code: <div class="boxInner"><h3>Arena Referees</h3><table class="list"><thead><tr><th style="width:16px;"></th><th style="width:150px;">Name</th><th style="width:300px;">Position</th><th style="width="150px;">Gamertag</th></tr></thead><tbody><tr><td><a href="http://gamebattles.com/profile/GottaHaveFaith78"><img src="http://media.gamebattles.com/icons/16/profile.png" class="icon16" /></a></td><td class="alt1">Faith</td><td><b>Head Referee</B></td><td class="alt1">GB CombatBarbie</td></tr><tr><td class="alt2"><a href="http://gamebattles.com/profile/Jack.-"><img src="http://media.gamebattles.com/icons/16/profile.png" class="icon16" /></a></td><td>Jack</td><td class="alt2"><b>Asst. Head Referee</b></td><td>Get Jacked x</td></tr><tr><td><a href="http://gamebattles.com/profile/amghawk"><img src="http://media.gamebattles.com/icons/16/profile.png" class="icon16" /></a></td><td class="alt1">Mike</td><td><b>Asst. Head Referee (IS)</b></td><td class="alt1">GB amghawk</td></tr><tr><td class="alt2"><a href="http://gamebattles.com/profile/cory94bailly"><img src="http://media.gamebattles.com/icons/16/profile.png" class="icon16" /></a></td><td>Cory</td><td class="alt2">Referee</td><td>Cory xz</td></tr><tr><td><a href="http://gamebattles.com/profile/crago"><img src="http://media.gamebattles.com/icons/16/profile.png" class="icon16" /></a></td> I'm just wondering how I could even count them. Any help will be appreciated, thanks. Quote Link to comment https://forums.phpfreaks.com/topic/211024-need-help-counting-rows-in-html-table/ Share on other sites More sharing options...
Pikachu2000 Posted August 18, 2010 Share Posted August 18, 2010 Does that mean you do not have direct access to the database? Quote Link to comment https://forums.phpfreaks.com/topic/211024-need-help-counting-rows-in-html-table/#findComment-1100594 Share on other sites More sharing options...
Cory94bailly Posted August 18, 2010 Author Share Posted August 18, 2010 Does that mean you do not have direct access to the database? Exactly. I have the same amount of access that everyone else has. I need to make it count the HTML table rows via the source. I am emphasizing html because I want people to know that it is not MySQL rows. Quote Link to comment https://forums.phpfreaks.com/topic/211024-need-help-counting-rows-in-html-table/#findComment-1100596 Share on other sites More sharing options...
jcbones Posted August 18, 2010 Share Posted August 18, 2010 There is surely an easier way to do the patterns, but I'm no regex guru. It is a bit sloppy, but it does work. <?php $str = file_get_contents('http://gamebattles.com/xbox360/call-of-duty-modern-warfare-2/support'); //get the page. $refPatt = '~<h3>Arena Referees</h3><table class="list">.*<tbody>(<tr>.*?</tr>)+</tbody>~'; $adminPatt = '~<h3>Arena Administrators</h3><table class="list">.*<tbody>(<tr>.*?</tr>)+</tbody>~'; preg_match_all($refPatt,$str,$ref); //match the table content. preg_match_all('~(<tr>)+~',$ref[0][0],$refTr); //count the table rows; $refCount = count($refTr[1]) - 1; //subtract 1 for the table header row. preg_match_all($adminPatt,$str,$admin); //match the table, gets both table's. preg_match_all('~(<tr>)+~',$admin[0][0],$adminTr); //counts the rows, gets both tables rows. $adminCount = (count($adminTr[1]) - $refCount) - 2; //subtract the last tables rows from the first table, and then subtract both table header rows. echo 'Admin\'s: ' . $adminCount . '<br />Referee\'s: ' . $refCount; //echo out the counts, I think you will find they are limiting these tables to 50 rows each. ?> Of course you could just say 50 ref's and 50 admins, because that is what the page has. I'm suspecting it is limited to show only that amount. Quote Link to comment https://forums.phpfreaks.com/topic/211024-need-help-counting-rows-in-html-table/#findComment-1100597 Share on other sites More sharing options...
Cory94bailly Posted August 18, 2010 Author Share Posted August 18, 2010 Of course you could just say 50 ref's and 50 admins, because that is what the page has. I'm suspecting it is limited to show only that amount. As far as I know, there's no limit. They couldn't show only part of the staff, that would cause alot of confusion. But thank you alot. It works nicely It's a chance for me to learn too I'll mark it resolved now. Quote Link to comment https://forums.phpfreaks.com/topic/211024-need-help-counting-rows-in-html-table/#findComment-1100600 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.