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

trying to hint towards the thing 

@nev what do you usually do when you want to reuse code?

@noiob none of my code should ever be re-used

(but seriously, I am only just starting to wrap my head around iterating over lists, so this is over my head)

Sign in to participate in the conversation
Awoo Space

Awoo.space is a Mastodon instance where members can rely on a team of moderators to help resolve conflict, and limits federation with other instances using a specific access list to minimize abuse.

While mature content is allowed here, we strongly believe in being able to choose to engage with content on your own terms, so please make sure to put mature and potentially sensitive content behind the CW feature with enough description that people know what it's about.

Before signing up, please read our community guidelines. While it's a very broad swath of topics it covers, please do your best! We believe that as long as you're putting forth genuine effort to limit harm you might cause – even if you haven't read the document – you'll be okay!