Instantly share code, notes, and snippets.

Embed
What would you like to do?
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