JLCongdon Posted October 29, 2009 Share Posted October 29, 2009 I am writing a site that does a NFL Pick 'em type application and I have a feed that gives me the scores of the NFL games every week I have it split apart down to each game two teams and a score directly after it... Here is what it is stripping the info from to begin with &nfl_s_left1=Houston%20at%20Buffalo%20(1:00%20PM%20ET) Here is the code: foreach($content_array as $content) { if (strpos($content, "_left")) { $count=0; $equalpos = strpos($content, "="); $end = strlen($content); $title = substr($content, ($equalpos+1), $end); $title = str_replace("^", "", $title); $title = str_replace("%20%20%20", "<br>",$title); $title = str_replace("%20", " ", $title); $game[$i]=$title; $scorearray[$i]["title"] = $title; $i++; } } Here is an example of what it looks like here is what it looks like after the game Houston 31 at Buffalo 30 (Final) And here is what it looks like before the game Houston at Buffalo (1:00 PM ET) The information that I need is team_home, team_home_score, team_away, team_away_score, game_status(Whether it is finished or what time the game is). Any ideas or anything would be great! Quote Link to comment Share on other sites More sharing options...
JLCongdon Posted October 29, 2009 Author Share Posted October 29, 2009 Here is an update! I got each team and their score separated. So now each is split like this... Houston 31 ($home[$i]) Buffalo 30 ($away[$i]) (Final) ($gameStatus[$i]) The three of those things are in different variables $game=array(); $home=array(); $away=array(); $gameStatus=array(); foreach($content_array as $content) { if (strpos($content, "_left")) { $count=0; $equalpos = strpos($content, "="); $end = strlen($content); $title = substr($content, ($equalpos+1), $end); $title = str_replace("^", "", $title); $title = str_replace("%20%20%20", "<br>",$title); $title = str_replace("%20", " ", $title); $game[$i]=$title; $scorearray[$i]["title"] = $title; $i++; $endHome = strpos($title, " at "); $home[$i] = substr($title,0,$endHome); $endAway = strpos($title, " ("); $away[$i] = substr($title,$endHome+4,$endAway-$endHome-4); $endStatus = strpos($title, ")"); $gameStatus[$i] = substr($title,$endAway+1,$endStatus); echo $home[$i]."<br>"; echo $away[$i]."<br>"; echo $gameStatus[$i]."<br>"; } } If anyone has any ideas on how to separate $home[$i] into $homeTeam[$i] and $homeScore[$i] that would be great! What I think it is going to take is for something to find the first numeral and then separate it to the score! Thanks! Quote Link to comment Share on other sites More sharing options...
mikesta707 Posted October 29, 2009 Share Posted October 29, 2009 to split home team and home score, just do $string = "New York 56"; $tokens = explode(" ", $string); echo "Home team: " . $tokens[0] . " Score: " . $tokens[1]; //echos Home team: New York Score: 56 Quote Link to comment Share on other sites More sharing options...
JLCongdon Posted October 29, 2009 Author Share Posted October 29, 2009 that is echoing "Home team: New Score: York" Quote Link to comment Share on other sites More sharing options...
mikesta707 Posted October 29, 2009 Share Posted October 29, 2009 oh yeah sorry, that won't work with a space between the city name. it will work for things like Ohio 65. let me make one that will work for getting the city name. Quote Link to comment Share on other sites More sharing options...
JLCongdon Posted October 29, 2009 Author Share Posted October 29, 2009 other than that it is PERFECT!!! Thank you so much I look forward to the next code that gets a city with a space!!! Quote Link to comment Share on other sites More sharing options...
mikesta707 Posted October 29, 2009 Share Posted October 29, 2009 function getScoreAndCity($string){ $tokens = explode(" ", $string); $name = array() foreach($tokens as $token){ if (is_numeric($token)){ $score = $token; } else { $name[] = $token; } } $name = implode(' ', $name); return array($name, $score); } Untested, but it should be about right Quote Link to comment Share on other sites More sharing options...
JLCongdon Posted October 29, 2009 Author Share Posted October 29, 2009 Parse error: syntax error, unexpected T_FOREACH in /data/4/0/150/14/313829/user/319211/htdocs/jeremy/football/rss/nfl.php on line 91 There is no $token for the foreach loop idk where to add that? Quote Link to comment Share on other sites More sharing options...
mikesta707 Posted October 29, 2009 Share Posted October 29, 2009 $token? do you mean $tokens? that is defined? post your code i dont know what your talking about Quote Link to comment Share on other sites More sharing options...
JLCongdon Posted October 29, 2009 Author Share Posted October 29, 2009 function getScoreAndCity($string){ $tokens = explode(" ", $string); //$tokens is defined $name = array() foreach($tokens as $token){ //$token is not here is where the error is if (is_numeric($token)){ $score = $token; } else { $name[] = $token; } } $name = implode(' ', $name); return array($name, $score); } Quote Link to comment Share on other sites More sharing options...
mikesta707 Posted October 29, 2009 Share Posted October 29, 2009 oh sorry missed a semi colon function getScoreAndCity($string){ $tokens = explode(" ", $string); //$tokens is defined $name = array();//missed it here foreach($tokens as $token){ //$token is not here is where the error is if (is_numeric($token)){ $score = $token; } else { $name[] = $token; } } $name = implode(' ', $name); return array($name, $score); } Quote Link to comment Share on other sites More sharing options...
JLCongdon Posted October 29, 2009 Author Share Posted October 29, 2009 How did I not see that!!! Thanks that is Perfect! I will post the final code after I finish up in case anyone wants to see how to use this in the future! Quote Link to comment 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.