是否有一种简单的方法将google产品分类列表转换为多维数组?
http://www.google.com/basepages/producttype/taxonomy.en-GB.txt到目前为止我有
$taxonomy = file_get_contents('assets/taxonomy.en-GB.txt');
$taxonomy = explode("n", $taxonomy);
array_shift($taxonomy);
但是这只是将它放入一个平面数组
又快又脏:
<?php
$file = file_get_contents('taxonomy.data');
$file = explode("n", $file);
$taxonomy = array();
foreach ($file as $index => $line) {
$fields = explode(" > ", $line);
$cursor = &$taxonomy;
foreach ($fields as $field) {
if (!isset($cursor[$field])) {
$cursor[$field] = array();
}
$cursor = &$cursor[$field];
}
}
print_r($taxonomy);
?>