<?php require_once '../lib.php'; $set = "Alara Reborn"; $file = fopen("AlaraReborn.txt", "r"); $card = array(); while (!feof($file)) { $line = fgets($file); if (preg_match("/^(.*):\\s+(.*)\$/", $line, $matches)) { $card[$matches[1]] = $matches[2]; if ($matches[1] == "Set/Rarity") { preg_match("/{$set} (Common|Uncommon|Rare)/", $card[$matches[1]], $submatches); $card[$matches[1]] = $submatches[1]; if ($card['Set/Rarity'] == 'Common') { insertCard($card, $set); } } } } function insertCard($card, $set) { $db = dbcon(); $cmc = getConvertedCost($card['Cost']); $isw = $isu = $isb = $isr = $isg = 0; if (preg_match("/W/", $card['Cost'])) { $isw = 1; } if (preg_match("/U/", $card['Cost'])) { $isu = 1; } if (preg_match("/B/", $card['Cost'])) {
// Insert the card set $stmt = $database->prepare("INSERT INTO cardsets(released, name, type) values(?, ?, ?)"); $stmt->bind_param("sss", $releasedate, $set, $settype); if (!$stmt->execute()) { echo "!!!!!!!!!! Set Insertion Error !!!!!!!!!<br /><br /><br />"; die($stmt->error); } else { echo "Inserted new set {$set}!<br /><br />"; } $stmt->close(); } $stmt = $database->prepare("INSERT INTO cards(cost, convertedcost, name, cardset, type,\n isw, isu, isb, isr, isg, isp, rarity) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);"); foreach ($data->cards as $card) { $cardsparsed++; if ($card->rarity === "Common") { insertCard($card, $set, $card->rarity, $stmt); $cardsinserted++; } } echo "End of File Reached<br />"; echo "Total Cards Parsed: {$cardsparsed}<br />"; echo "Total Cards Inserted: {$cardsinserted}<br />"; $stmt->close(); function insertCard($card, $set, $rarity, $stmt) { # new gatherer - card type is now a . because of unicode $typeline = join($card->types, " "); if (count($card->subtypes) > 0) { $typeline = $typeline . " - " . join($card->subtypes, " "); } echo "<table class=\"new_card\">";