Jump to content

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/179436-seperate-team-from-score/
Share on other sites

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!

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

 

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);
}

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);
}

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.