58 echo
"CSV to HTML structure tree converter\n\n";
59 echo
"Usage: csv_to_html_tree [csv file]\n";
60 echo
"csv file: A comma separated values file that represents the site structure\n\n";
67 if ((php_sapi_name() !=
'cli')) {
68 trigger_error(
"You can only run this script from the command line\n", E_USER_ERROR);
72 $csv_filename = $argv[1];
73 if (empty($csv_filename)) {
75 echo
"* A CSV filename must be specified as the first parameter\n\n";
80 $fd = fopen($csv_filename,
'r');
83 echo
"* The supplied CSV file was not found\n\n";
88 $last_html_tree = Array();
90 while (($data = fgetcsv($fd, 1024,
',')) !== FALSE) {
93 $num_fields = count($data);
97 foreach ($data as $key => $val) {
99 $html_tree[$current_level] = $val;
103 foreach ($html_tree as $level => $page_name) {
104 $current_page = $html_tree[$level];
106 if (!empty($page_name)) {
107 if ($page_name != $last_html_tree[$level]) {
109 echo
'<h'.$level.
'>'.trim($page_name).
'</h'.$level.
">\n";
116 $last_html_tree = $html_tree;