How to properly nest lists in HTML; in which nev tries to code (PHP) 

it was only this year I learned that the proper way to nest lists in HTML is

<ul>
<li>Item
<ul><li>Sub-item</li><ul>
</li>
</ul>

and not

<ul>
<li>Item</li>
<ul><li>Sub-item</li></ul>
</ul>

which makes sense and all, but it is making things hard for me because I am trying to write a thing in PHP that generates a table of contents (a list of nested links) from a web page's headings, and I am having a DICKENS of a time. I figured out how to tell it to *start* a nested list, but I am having trouble figuring out how to close the containing </li> tags correctly. Especially in cases where the list goes from, like, <h4> to <h2>. Do I have to, like, nest the LOOPS too?

I do want to figure it out by myself but if anyone has dealt with this particular problem, hints would be welcome!

#html #php #codeing

Follow

@nev the closing </li> is optional unless you're doing xhtml or building <menu> with mixed content. if you have problems with them, just skip them

Sign in to participate in the conversation
CleverLibre Social

CleverLibre Social is an inclusive social instance for open discussion, learning, and community.
All cultures welcome.
Hate speech and harassment strictly forbidden.