I'm trying to break down a rss feed with sports scores
Example data
San Diego 4 Chicago Cubs 2
Miami 2 Philadelphia 7
Boston 3 Toronto 1
Washington 3 Atlanta 1
Chicago Sox 3 Texas 1
St. Louis 6 Milwaukee 5
The rss basically gives me one flowing string like San Diego 4 Chicago Cubs 2
and i'm trying to break it down for better use.
Basically im trying to first split San Diego 4 Chicago Cubs 2
into four variables, $home_team
, $home_score
, $away_team
, $away_score
.
But, obviously the home team could be one word or more, the score could be 1 digit or up to 3 so i've been trying to figure out the best regular expression to split this up in the correct format.
Does anyone have any ideas?
Update
Code that i'm actually using this for, i'm pulling xml of mlb games today, filtering out just the games that are labeled as Final meaning Final Score and then im trying to break it down further from there..
<?php
$xml = simplexml_load_file("http://feeds.feedburner.com/mpiii/mlb?format=xml");
foreach($xml->channel->item as $item){
if(preg_match('/(FINAL)/', $item->title, $matches) || preg_match('/(POSTPONED)/', $item->title, $matches)){
if(preg_match('/(POSTPONED)/', $item->title, $matches)){
continue;
}
$string = $item->title;
$patterns = array();
$patterns[0] = '/\\(FINAL\\)/';
$patterns[1] = '/\\(POSTPONED\\)/';
$replacements = array();
$replacements[1] = '';
$replacements[0] = '';
$string = preg_replace($patterns, $replacements, $string);
$keywords = preg_match("^(.*?) ([0-9]{1,3}) (.*?) ([0-9]{1,3})$", $string);
echo $keywords[1]."<br/>";
}
}
?>