EDIT: Ok I am a bit closer but still need help… http://pastebin.com/9vdhGT2V
Disclaimer: This is my first post after using SO as a resource for quite a while. I am not being lazy I just have exhausted search and I’m close I just need a nudge from some friendly more experienced coders. Thanks in advance!
I am using Simple HTML DOM to run out to Yahoo Sports and grab scores. What I am having trouble with is grouping the two teams that are play together in a table. I know that I will need to count by 2 as it is very predictable I am just having trouble forming it correct.
This is the last piece of working code I have but it does not group by teams playing each other:
<?php
require('simple_html_dom.php');
$nbaScores = "http://sports.yahoo.com/nba/scoreboard";
$html = file_get_html($nbaScores);
// Find all game info
foreach($html->find('tr.ysptblclbg5') as $scores){
echo "<table><tr><td>".$scores->find('td',0)->plaintext. "</td>";
echo "<td>".$scores->find('td',1)->plaintext. "</td>";
echo "<td>".$scores->find('td',2)->plaintext. "</td>";
echo "<td>".$scores->find('td',3)->plaintext. "</td>";
echo "<td>".$scores->find('td',4)->plaintext. "</td>";
echo "<td>".$scores->find('td',5)->plaintext. "</td>";
echo "<td>".$scores->find('td',6)->plaintext. "</td>";
echo "<td>".$scores->find('td',7)->plaintext. "</td></tr></table>";
}
unset($scores);
?>
Cheers!
Edit: the code will now reflect the overtime optional TD. I assume $parse->find(“tag[attribute=value]”) returns a table of objects that implement ->plaintext.
Edit#2: the code will now know which team won a match (using a subtable of $teams).
Edit#3: based on comments: corrected parenthesis, corrected the team shifting in the table from edit#1
Never used that parser, so assuming your parsing methods work (and assuming I didn’t get confused in the TD indexes), but anyway here’s the logics:
There you have 2 tables with teams and scores parsed accordingly to each match. Now you can print them the way you want:
I didn’t test this code, so there might be some mistypings, but the purpose is for you to have a hint on how to parse the thing in tables, which is easier if you want to focus on your display 😉
However… I have no legal advice for you, sorry ^^