我有一棵目录、子目录和文件(在一些但不是所有目录中)。这是整个树的示例:
/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
好的,从 '/' 目录中的 php 脚本,我想递归或遍历这个目录树并像这样打印树:
<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>
<li>red.html</li>
<li>pink.html</li>
<li>purple.html</li>
</ul>
</ul>
</ul>
</ul>