I need to split the content in php into an (json-)array. I.e. I want to get out of this:
<p>Text Level 0</p>
<section class="box_1">
<header class="trigger"><h2>Title</h2></header>
<div class="content">
<div class="box_2">
<div class="class"></div>
<div class="content">
<p>Text Level 2</p>
<p>More Text Level 2</p>
</div>
</div>
<div class="box_2">
<div class="class"></div>
<div class="content">
<p>Text Level 2</p>
<div class="box_3">
<div class="content">
<p>Text Level 3</p>
</div>
</div>
</div>
</div>
</div>
</section>
<p>Another Text</p>
This result:
0: "Text Level 0"; 2: "Text Level 2\nMore Text Level 2"; 2: "Text Level 2"; 3: "Text Level 3"; 0: "Another Text";
That means I need the "Level" of the Text, and the Text itself. But I don't know how to do that. Should I use RegExp or should I parse the content (i.e. simple_html_dom.php)?
Something like:
- Check for every p-element in "content"-class
- Check the closest "box_*"-class -> Level-number
- Summarize all elements of the same "content"
- If p-element is not in "content" -> Level 0
But how can I do that in php?
2multiple times in the same array.