(.*?).*?
.*?(.*?) |is';
//search the string for the pattern, and store the content found inside the set of parens in the array $matches
//$matches[1] is going to hold team names in the order they appear on the page, and $matches[2] the scores
preg_match_all($find, $string, $matches);
//initiate scores array, to group teams and scores together in games
$scores = array();
//count number of teams found, to be used in the loop below
$count = count($matches[1]);
//loop from 0 to $count, in steps of 2
//this is done in order to group 2 teams and 2 scores together in games, with each iteration of the loop
//trim() is used to trim away any whitespace surrounding the team names and scores
//strip_tags() is used to remove the HTML bold tag () from the winning scores
for ($i = 0; $i < $count; $i += 2) {
$away_team = trim($matches[1][$i]);
$away_score = trim($matches[2][$i]);
$home_team = trim($matches[1][$i + 1]);
$home_score = trim($matches[2][$i + 1]);
$winner = (strpos($away_score, '<') === false) ? $home_team : $away_team;
$scores[] = array(
'awayteam' => $away_team,
'awayscore' => strip_tags($away_score),
'hometeam' => $home_team,
'homescore' => strip_tags($home_score),
'winner' => $winner
);
}
echo "
";
echo "Scores from week: $Current_Week";
echo " ";
echo " ";
//see how the scores array looks
echo '' . print_r($scores, true) . ' ';
//game results and winning teams can now be accessed from the scores array
//e.g. $scores[0]['awayteam'] contains the name of the away team (['awayteam'] part) from the first game on the page ([0] part)
?>
|