"; if (!file_exists("trivia_json_" . $sh . ".php")) { // Excel reader from http://code.google.com/p/php-excel-reader/ require('php-excel-reader/excel_reader2.php'); require('SpreadsheetReader.php'); date_default_timezone_set('UTC'); $StartMem = memory_get_usage(); /* echo '---------------------------------'.PHP_EOL; echo 'Starting memory: '.$StartMem.PHP_EOL; echo '---------------------------------'.PHP_EOL; */ $Filepath = "trivia.xlsx"; //Initialize array variable $dbdata = array(); try { $Spreadsheet = new SpreadsheetReader($Filepath); $BaseMem = memory_get_usage(); $Sheets = $Spreadsheet -> Sheets(); /* echo '---------------------------------'.PHP_EOL; echo 'Spreadsheets:'.PHP_EOL; print_r($Sheets); echo '---------------------------------'.PHP_EOL; echo '---------------------------------'.PHP_EOL; */ foreach ($Sheets as $Index => $Name) { /* echo '---------------------------------'.PHP_EOL; echo '*** Sheet '.$Name.' ***'.PHP_EOL; echo '---------------------------------'.PHP_EOL; */ if ($Name ==$sh) { $Time = microtime(true); $Spreadsheet -> ChangeSheet($Index); foreach ($Spreadsheet as $Key => $Row) { /* echo $Key.': '; if ($Row) { print_r($Row); } else { var_dump($Row); } */ //array_push($aryQuestions, $Row[2]); //array_push($aryAnswers, $Row[1]); //array_push($aryIndex, $Row[0]); //echo $Row[3] . "
"; $CurrentMem = memory_get_usage(); /* echo 'Memory: '.($CurrentMem - $BaseMem).' current, '.$CurrentMem.' base'.PHP_EOL; echo '---------------------------------'.PHP_EOL; */ if ($Key && ($Key % 500 == 0)) { /* echo '---------------------------------'.PHP_EOL; echo 'Time: '.(microtime(true) - $Time); echo '---------------------------------'.PHP_EOL; */ } $dbdata[]=$Row; } /* echo PHP_EOL.'---------------------------------'.PHP_EOL; echo 'Time: '.(microtime(true) - $Time); echo PHP_EOL; echo '---------------------------------'.PHP_EOL; echo '*** End of sheet '.$Name.' ***'.PHP_EOL; echo '---------------------------------'.PHP_EOL; */ } } } catch (Exception $E) { echo $E -> getMessage(); } //echo json_encode($dbdata); $str_json = json_encode($dbdata, JSON_FORCE_OBJECT); //echo $str_json . "
"; //echo json_last_error_msg($str_json); file_put_contents("trivia_json_" . $sh . ".php", "<" . "? if (1==2) { ?" . ">" . $str_json . "<" . "? } ?" . ">"); echo "Excel
"; } //echo "Read Json
"; $trivia_json = str_replace("<" . "? if (1==2) { ?" . ">", "", str_replace("<" . "? } ?" . ">", "", file_get_contents("trivia_json_" . $sh . ".php"))); //echo ""; $json = json_decode($trivia_json, true); //var_dump(json_last_error()); //echo $trivia_json; //var_dump($json); foreach ($json as $field => $Row) { // Use $field and $value here //print_r($Row); if (intval($Row[0])==0) { $strTriviaName = $Row[1]; $strTriviaTitle = $Row[2]; $strTriviaTitle = str_replace("Questions with Answers", "", $strTriviaTitle); $strTriviaTitle = str_replace("Questions and Answers", "", $strTriviaTitle); $strTriviaTitle = str_replace("Questions With Answers", "", $strTriviaTitle); } else { array_push($aryQuestions, $Row[2]); array_push($aryAnswers, $Row[1]); array_push($aryIndex, $Row[0]); } } ?> 0) { $tl_score += intval($value); } } $cur = $_REQUEST["cur"]; $tl = $_REQUEST["tl"]; if ($tl=="") { $tl = sizeof($aryIndex); } $nx = 1; if ($cur=="") { $cur = "1"; } $cur = intval($cur); $nx = intval($cur) + 1; $percent = round($cur/$tl*100); //print_r($aryQuestions); //print_r($aryAnswers); //print_r($aryIndex); //echo "
"; //echo "----" . $cur . "-" . $nx . "
"; //echo "====" . (intval($aryIndex[$cur-1])-1) . "
"; //echo ">>>>" . $cur-1 . "
"; //echo ">>>>" . $cur-1 . "
"; //echo "++++" . $aryQuestions[(intval($aryIndex[$cur-1])-1)] . "
"; /* */ ?>
Total Score: " . $tl_score;?>