Skip to content

Instantly share code, notes, and snippets.

@ircykk
Created May 22, 2018 16:40
Show Gist options
  • Save ircykk/71f011fda44852d5adf686dc9e9f0efd to your computer and use it in GitHub Desktop.
Save ircykk/71f011fda44852d5adf686dc9e9f0efd to your computer and use it in GitHub Desktop.
Ceneo Xml categories recurse extract
<?php
$catgoriesXmlPath = __DIR__.'/ceneo-categories.xml';
$xml = simplexml_load_string(file_get_contents($catgoriesXmlPath));
$out = [];
foreach($xml->Category as $xmlCategory) {
recurseExtract($out, '', $xmlCategory);
}
function recurseExtract(&$out, $fullPath, $xmlCategory) {
$fullPath = ($fullPath ? $fullPath.' / ' : '').(string)$xmlCategory->Name;
$out[] = $fullPath;
if ($xmlCategory->Subcategories) {
foreach($xmlCategory->Subcategories->Category as $xmlSubCategory) {
recurseExtract($out, $fullPath, $xmlSubCategory);
}
}
}
file_put_contents('./categories.csv', implode(PHP_EOL, $out));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment