Created
May 22, 2018 16:40
-
-
Save ircykk/71f011fda44852d5adf686dc9e9f0efd to your computer and use it in GitHub Desktop.
Ceneo Xml categories recurse extract
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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