46 function indent_list_to_array(&$lines)
49 $indent_size = get_indent_size(current($lines));
51 $current_line = current($lines);
53 $line_content = trim($current_line);
54 if (get_indent_size($current_line) < $indent_size) {
57 if (
false === next($lines))
break;
58 if (empty($line_content))
continue;
59 if (get_indent_size(current($lines)) > $indent_size) {
60 $res[$current_line] = indent_list_to_array($lines);
62 $res[$current_line] = Array();
80 function get_indent_size($s)
83 while ($s{$res} ==
"\t") {
100 function print_array_xml_r($res, $indent=
'')
105 foreach ($res as $item => $kids) {
106 echo $indent.
'<term name="'.htmlspecialchars(trim($item)).
'">';
109 echo $indent.
"\t".
'<relation name="Category">'.
"\n";
110 print_array_xml_r($kids, $indent.
"\t\t");
111 echo $indent.
"\t".
'</relation>'.
"\n";
123 echo
"Usage: php indent_list_to_xml inputfile.txt > outputfile.xml \n";
129 $lines = file($argv[1]);
131 $res = indent_list_to_array($lines, $res);
132 print_array_xml_r($res,
"\t\t");