Skip to content

Instantly share code, notes, and snippets.

@vetleledaal
Last active January 12, 2019 21:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vetleledaal/c357f803719a181f8d7de4e810ad909d to your computer and use it in GitHub Desktop.
Save vetleledaal/c357f803719a181f8d7de4e810ad909d to your computer and use it in GitHub Desktop.
Creates a csv file containing the article name and main Steam AppID from exports of PCGW.
<?php
$fp = fopen('pcgw_steam_ids.csv', 'w');
// For each xml file exported from PCGW ...
foreach(glob('*.xml') as $filename) {
$file_contents = file_get_contents($filename);
// Find every title and steam appid pairs
preg_match_all('%<title>([^<]+)<(?:(?!</text>).)+?\|steam appid\s*= *([^\r\n]*)%sm', $file_contents, $results);
$count = count($results[1]);
for($i=0; $i < $count; $i++) {
// Only add valid steam appids to the csv file
if(preg_match('%^[1-9]\d*%', $results[2][$i], $match_id) === 1) {
fputcsv($fp, [html_entity_decode($results[1][$i], ENT_QUOTES | ENT_HTML5), $match_id[0]]);
}
}
}
fclose($fp);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment