Jump to content
The Official Site of the Vancouver Canucks
Canucks Community

Any programmers here? (PHP)


Patrick Kane

Recommended Posts

I'm just starting to learn programming, and have been using my skills for my fantasy sim league on CDC. One thing I've been doing is typing out box scores, and then inputting the stats manually into a table MYSQL database: http://rgmg.tk/
It's not bad, but I'd love to make a script/program that I can paste the boxscores into and it automatically parses and inputs the stats for me.
General ideas:
Input box score into a form.
$boxscore =
"CHI 3 - MIN 0
1st
CHI - Kane (Seabrook, Toews)
2nd
CHI - Kane (Seabrook, Toews)
3rd
CHI - Kane (Seabrook, Toews)"
1.
Loop through the scores, and add to goal column for goal scorers.
Parse the information to only grab between " - " and " ("
Make this variable = $goalscorer
INSERT INTO `goals` VALUE (`goals` + 1) WHERE `name` LIKE $goalscorer
2.
Loop through the scores, and add primary assist
Parse the information to only grab between " (" and ","
Loop through the scores, and add secondary assist
Parse the information to only grab between ", " and ")"
Make these variables = $assist1 and $assist2
INSERT INTO `assists` VALUE (`assists` + 1) WHERE `name` LIKE $assist1 / $assist2
_______________________________________________________
So what do you guys think? What is the best function to parse all the information, and what kind a loop should be used?
All the participants in my league, and I would greatly appreciate some suggestions! :)
Link to comment
Share on other sites

Use regular expressions, probably preg_match: http://php.net/manual/en/function.preg-match.php

It'll take your regular expression (arg1) and search whatever string you want (arg2) and return an array of matches (arg3).

Source: I'm the lead programmer of a PHP-driven fantasy hockey website called Fantasy Hockey Geek.

Wow, just my luck! :)

Your site looks fantastic, how many years of programming experience do you have?

I will look into preg_match, and see if I can parse the boxscore as my first step. Hope you're okay with asking you more questions in the future.

Thanks man

Link to comment
Share on other sites

Wow, just my luck! :)

Your site looks fantastic, how many years of programming experience do you have?

I will look into preg_match, and see if I can parse the boxscore as my first step. Hope you're okay with asking you more questions in the future.

Thanks man

No problem. Regular expressions seem a bit overwhelming at first, but once you get the hang of them they're very powerful.

I've been programming PHP for about 10 years. I did it for a living for the first six. I have a different career now but still do it on the side.

Link to comment
Share on other sites

I'm more of a WordPress programmer, but you could try setting up an array:

$stats = array();

$stats[] = array(
	'1' => array(
		'goal'=>'Patrick Kane', 
		'primary_assist' => 'Jonathan Toews',
		'secondary_assist' => 'Duncan Keith'
	),
	'2' => array(
		'goal'=>'Jonathan Toews', 
		'primary_assist' => 'Duncan Keith',
		'secondary_assist' => 'Patrick Kane'
	)
);

foreach ( $stats as $stat ) {
	$goal = $stat['goal'];
	$assist = $stat['primary_assist'];
	$second_assit = $stat['secondary_assist'];
}
Link to comment
Share on other sites

No problem. Regular expressions seem a bit overwhelming at first, but once you get the hang of them they're very powerful.

I've been programming PHP for about 10 years. I did it for a living for the first six. I have a different career now but still do it on the side.

Got it working! Haven't implemented a form yet (that's easy), but I got it to parse line by line, with 3 'ifs' - 2 assists, 1 assist, and unassisted.

Now the issue is with players like Sedins, and Johnson. Since there are multiple entries of them in the database.

H.Sedin
- replace '.' with space - DONE
H Sedin
- add ', ' in front - DONE
, H Sedin
- move first 3 characters to end of string.
Sedin, H
Not sure how I'd go about this the thing above.
Link to comment
Share on other sites

Got a solution, sloppy code - but it'll do the job.

if (strpos($goalscorer,'.') !== false) {
$goal = str_replace(".", " ", $goalscorer);
$goal2 = ", " . $goal;
$goal3 = wordwrap($goal2, 6, "!", true);
$goal4 = explode("!", $goal3);
$initials = $goal4[0];
$lastname = $goal4[1];
$goalscorer = $lastname . $initials;
echo "$goalscorer";
echo "<br>";
echo "<br>";
Link to comment
Share on other sites

Unfamiliar with WordPress and its functions, but if it's any help you can parse H.Sedin to Sedin, H with JavaScript like so:

var name = "H.Sedin";

var parsed = name.split(".").reverse().join(", ");



Basically split the name string by "." so you get ["H", "Sedin"]. Then reverse the array. Then join it using ", " so you get the string "Sedin, H". Only had time to read through your last post, so sorry if this isn't what you're looking for. Thought I'd try and help anyway.

Link to comment
Share on other sites

Unfamiliar with WordPress and its functions, but if it's any help you can parse H.Sedin to Sedin, H with JavaScript like so:

var name = "H.Sedin";

var parsed = name.split(".").reverse().join(", ");



Basically split the name string by "." so you get ["H", "Sedin"]. Then reverse the array. Then join it using ", " so you get the string "Sedin, H". Only had time to read through your last post, so sorry if this isn't what you're looking for. Thought I'd try and help anyway.

I'm using PHP, do you know how to do it in that?

I'm not using Wordpress :P the other guy is

Link to comment
Share on other sites

Woops, I meant PHP sorry. Not too familiar with PHP but upon googling it seems like you can do something like

$name = "H.Sedin";
$name_split = explode(".", $name);
$name_reversed = array_reverse($name_split);
$name = implode(", ", $name_reversed);

Again, my syntax and variable declarations could be wrong since I'm unfamiliar with PHP. But I hope that helps.

Link to comment
Share on other sites

Woops, I meant PHP sorry. Not too familiar with PHP but upon googling it seems like you can do something like

$name = "H.Sedin";
$name_split = explode(".", $name);
$name_reversed = array_reverse($name_split);
$name = implode(", ", $name_reversed);

Again, my syntax and variable declarations could be wrong since I'm unfamiliar with PHP. But I hope that helps.

WOW. Worked beautifully.

Your code is 100x better than mine! Thanks alot man :)

Link to comment
Share on other sites

Use regular expressions, probably preg_match: http://php.net/manual/en/function.preg-match.php

It'll take your regular expression (arg1) and search whatever string you want (arg2) and return an array of matches (arg3).

Source: I'm the lead programmer of a PHP-driven fantasy hockey website called Fantasy Hockey Geek.

Nice site literaphile...

Now if you only needed some help with Excel Visual Basic...

Very little exp with PHP...

Nice Post!

Good luck!

I'm more of a WordPress programmer, but you could try setting up an array:

$stats = array();

$stats[] = array(
	'1' => array(
		'goal'=>'Patrick Kane', 
		'primary_assist' => 'Jonathan Toews',
		'secondary_assist' => 'Duncan Keith'
	),
	'2' => array(
		'goal'=>'Jonathan Toews', 
		'primary_assist' => 'Duncan Keith',
		'secondary_assist' => 'Patrick Kane'
	)
);

foreach ( $stats as $stat ) {
	$goal = $stat['goal'];
	$assist = $stat['primary_assist'];
	$second_assit = $stat['secondary_assist'];
}

Unfamiliar with WordPress and its functions, but if it's any help you can parse H.Sedin to Sedin, H with JavaScript like so:

var name = "H.Sedin";

var parsed = name.split(".").reverse().join(", ");



Basically split the name string by "." so you get ["H", "Sedin"]. Then reverse the array. Then join it using ", " so you get the string "Sedin, H". Only had time to read through your last post, so sorry if this isn't what you're looking for. Thought I'd try and help anyway.

Finished product!

GKhlc1p.png

1H5HCPU.png

tdqCgjx.png

Link to comment
Share on other sites

Now you just need to account for situations like J. Benn (Jamie) and J. Benn (Jordie) playing for the same team. :)

No problem, glad I could help : ) Good luck.

I want my script to update standings now, and 'GP' for players.

ANA 4 - COL 0
Parse the text field. Store these fields as variables.
ANA - $winner
4 - $winnerG
COL - $loser
0 - $loserG
Need to convert the team abbreviations to their fullnames.
ANA => Anaheim
COL => Colorado
UPDATE `standings` SET `win` = (`win` + 1) WHERE `team` = "$winner"
UPDATE `standings` SET `gf` = (`goalsFor` + "$winnerG") WHERE `team` = "$winner"
UPDATE `standings` SET `ga` = (`goalsAgaisnt` + "$loserG") WHERE `team` ="$winner"
UPDATE `players` SET `gp` = (`gp` + 1) WHERE `team` = "$winner"
UPDATE `standings` SET `lose` = (`lose` + 1) WHERE `team` = "$loser"
UPDATE `standings` SET `gf` = (`goalsFor` + "$loserG") WHERE `team` = "$loser"
UPDATE `standings` SET `ga` = (`goalsAgaisnt` + "$winnerG") WHERE `team` = "$loser"
UPDATE `players` SET `gp` = (`gp` + 1) WHERE `team` = "$loser"
/////////////
ANA - COL 0 OT
IF ELSE statement if there is an 'OT' then would be the same except:
UPDATE `standings` SET `otl` = (`otl` + 1) WHERE `team` = $loser
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...