Skip to content

Instantly share code, notes, and snippets.

@vojtasvoboda
Created December 4, 2015 13:39
Show Gist options
  • Save vojtasvoboda/ab7da1eed9ed79774427 to your computer and use it in GitHub Desktop.
Save vojtasvoboda/ab7da1eed9ed79774427 to your computer and use it in GitHub Desktop.
xml2csv
<?php
include_once('vendor/autoload.php');
// debugger
use Tracy\Debugger;
Debugger::enable(Debugger::DEVELOPMENT, __DIR__ . '/log');
// load file
$content = file_get_contents(__DIR__ . '/data/data.xml');
$xml = new SimpleXMLElement($content);
// iterate items
echo '<html><head><title>csv2xml</title><meta charset="utf-8" /></head><body><table><br />';
foreach($xml->channel->item as $item) {
if( empty($item->ggtin)) {
echo '<tr>';
echo '<td>' . $item->gid . "</td><td>" . $item->title . "</td><td>" . $item->link . '</td>';
echo '</tr><br />';
}
}
echo '</table></body></html>';
exit('ok');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment