EOF;
print $form ;
}
else {
$ext=array() ;
$usedExt=array() ;
$cards=array() ;
$csvfile = fopen('cards.csv', "r") or die( "unable to open card file" ) ;
while( $line = fgetcsv( $csvfile ) ){
array_push( $ext, $line[0] );
array_push( $cards, $line[2] ) ;
}
$turns = 0 ;
$winner = "" ;
$first = "" ;
$data = trim( $_POST["log"] ) ;
$data_ar = preg_split("/\r\n|\n|\r/", $data);
foreach ($data_ar as $line ) {
if( strpos( $line, "ends turn" ) ) {
static $turns ;
$turns++ ;
}
if ( strpos( $line, "ends turn 1" ) ) {
$line_a = explode( " ", "$line" ) ;
$winner = $line_a[0] ;
}
if( preg_match( '/^Played (.*)<\/color>/', $line, $match ) ) {
guessExpansion( $match[1], $cards, $ext ) ;
}
if ( strpos( $line, "===" ) ) {
$line_a = explode( " ", "$line" ) ;
$first = $line_a[9] ;
}
}
echo "
" ;
echo "\n";
echo "\n";
echo "\n";
echo "first player is: $first
";
echo "winner is: $winner
" ;
echo "num of turns: $turns
" ;
echo "list of expansions used:" ;
echo "" ;
foreach ( array_unique($usedExt) as $e ){
print( "- ".$e."
" ) ;
}
echo "
" ;
}
function guessExpansion( $card, $cards, $ext ) {
global $usedExt ;
if( $key = array_search( $card, $cards)){
array_push( $usedExt, $ext[$key] ) ;
}
}