Skip to content

Instantly share code, notes, and snippets.

@bouchard
Created April 8, 2010 15:16
Show Gist options
  • Save bouchard/360172 to your computer and use it in GitHub Desktop.
Save bouchard/360172 to your computer and use it in GitHub Desktop.
<?php
header('Content-type: text/csv; charset=utf-8');
$xml = simplexml_load_file('mnemosyne.xml');
$lines = array();
foreach($xml->item as $item) {
$q = $item->Q;
$q = strip_tags((string) $q, '<u><ul><li>');
$q = str_replace('<dt>','',$q);
$q = str_replace('"', '\"', $q);
$a = $item->A;
$a = strip_tags((string) $a, '<u><li><ul>');
$a = str_replace('<u>','**', $a);
$a = str_replace('</u>','**', $a);
$a = str_replace('<dt>','',$a);
$a = str_replace('"', '\"', $a);
$a = preg_replace('/&lt;font size=2&gt;/','', $a);
$a = str_replace('• ','* ',$a);
$lines[(string) $item->cat][] = array($q, $a);
}
foreach($lines as $cat => $value) {
foreach($value as $qanda) {
echo("\"" . $qanda[0] . "\",\"" . $qanda[1] . "\"\n");
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment