Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $set = urlencode($argv[1]);
- $url = "http://magic.tcgplayer.com/db/search_result.asp?Set_Name=" . $set;
- $page = file_get_contents($url);
- preg_match('|<table width=540 cellpadding=1 cellspacing=0 border=0 align=center>(.*)</table>|Usi', $page, $matches);
- // Minor formatting tweaks: stripping tags, removing unneeded whitespace
- $page = strip_tags($matches[1], '<tr><td>');
- $page = str_replace(array(" ", "\t", "\n", "\r"), "", $page);
- $page = preg_replace("|<t[^>]+>|", "", $page);
- // Actual data formatting
- $page = str_replace("</td>", "|", $page); // Column delimiter
- $page = str_replace("</tr>", "\n", $page); // Record delimiter
- $page = str_replace("|\n", "\n", $page); // Remove extra delimiter
- // Final format: CSV
- // Card Name, Casting Cost, Set Name, Rarity, High, Mid, Low
- $lines = explode("\n", $page);
- $stdout = fopen("php://stdout", "w");
- foreach ($lines as $l) {
- fputcsv(STDOUT, explode("|", $l));
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement