D
D
DireX2015-05-21 18:42:45
PHP
DireX, 2015-05-21 18:42:45

How to convert nested html lists to php array?

Good evening.
There is an html list in the format

<ul>
  <li>Item 1
    <ul>
      <li>item 1.1</li>
      <li>item 1.2
        <ul>
          <li>item 1.2.1</li>
          <li>item 1.2.2</li>
          <li>item 1.2.3
            <ul>
              <li>item 1.2.3.1</li>
            </ul>
          </li>
        </ul>
      </li>
      <li>item 1.3</li>
    </ul>
  </li>
  <li>Item 2</li>
  <li>Item 3
    <ul>
     <li>Item 3.1</li>
    </ul>
  </li>
</ul>

How to use PHP (or other tools) to make an array from such a list with the corresponding hierarchy (parent, child).
Tags can contain classes or other unknown attributes.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Ineshin, 2015-05-21
@xDireX

On the client, this structure is a DOM tree that can be perfectly parsed recursively. To understand what is what, which node is nested, which is not, this article will help you: www.w3schools.com/jsref/prop_node_nodetype.asp
Well, this is also:
www.w3schools.com/jsref/prop_node_nodename.asp
www.w3schools .com/jsref/prop_node_nodevalue.asp
www.w3schools.com/jsref/prop_node_childnodes.asp

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question