RecursiveIteratorIterator и RecursiveDirectoryIterator для вложенных html-списков

Вот мой php-скрипт:

<?php

$path = $_SERVER['DOCUMENT_ROOT'].'/test';

$objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::SELF_FIRST);

foreach($objects as $name => $object){  
    echo  $objects->getDepth() . " " . $object->getFilename() . "<br/>";
    }

?>

Вот дерево каталогов/файлов, по которым перебирает скрипт. (Он находится в тривиальном корневом каталоге с именем $_SERVER['DOCUMENT_ROOT'].'/test'):

/food
/food/drinks
/food/drinks/water.html
/food/drinks/milk.html
/food/drinks/soda.html
/food/entrees
/food/entrees/hot
/food/entrees/hot/hamburger.html
/food/entrees/hot/pizza.html
/food/entrees/cold
/food/entrees/cold/icecream.html
/food/entrees/cold/salad.html
/cosmetics
/cosmetics/perfume
/cosmetics/perfume/chic.html
/cosmetics/perfume/polo.html
/cosmetics/perfume/lust.html
/cosmetics/lipstick
/cosmetics/lipstick/colors
/cosmetics/lipstick/colors/red.html
/cosmetics/lipstick/colors/pink.html
/cosmetics/lipstick/colors/purple.html

Вот что выводит сценарий:

0 food
1 drinks
2 milk.html
2 water.html
2 soda.html
1 info.php
1 entrees
2 hot
3 pizza.html
3 hamburger.html
2 cold
3 ice_cream.html
3 salad.html
0 cosmetics
1 lipstick
2 colors
3 pink.html
3 red.html
3 purple.html
1 perfume
2 polo.html
2 lust.html
2 chic.html
0 error_log
0 test.php

Игнорировать целое число $objects->getDepth(); это просто для справки

Вопрос: Как я могу модифицировать свой сценарий для вывода вложенных неупорядоченных списков, например:

<ul>
  <li>food</li>
    <ul>
      <li>drinks</li>
        <ul>
          <li>water.html</li>
          <li>milk.html</li>
          <li>soda.html</li>
        </ul>
      <li>entrees</li>
        <ul>
          <li>hot</li>
            <ul>
              <li>hamburger.html</li>
              <li>pizza.html</li>
            </ul>
          <li>cold</li>
            <ul>
              <li>icecream.html</li>
              <li>salad.html</li>
            </ul>      
        </ul>
    </ul>
  <li>cosmetics</li>
    <ul>
      <li>perfume</li>
        <ul>
          <li>chic.html</li>
          <li>polo.html</li>
          <li>lust.html</li>
        </ul>
      <li>lipstick</li>
        <ul>
          <li>colors</li>
            <ul>

Спасибо!

6
задан user743094 28 May 2012 в 05:00
поделиться