How to convert a tree of HTML tags in a PHP array?

Good evening. There is a HTML file that takes a function file_get_contents and printida print_r ($file);
The output contents with this HTML structure:
cd9054a333.png
Task: to convert this structure into a PHP array and split each tag on the elements in the array.
What to do:
Tried to convert the structure into an array using the following code:
$buffer = file_get_contents("link");

function XML2Array(SimpleXMLElement $parent)
{
 $array = array();

 foreach ($parent as $name => $element) {
 ($node = & $array[$name])
 && (1 === count($node) ? $node = array($node) : 1)
 && $node = & $node[];

 $node = $element->count() ? XML2Array($element) : trim($element);
}

 return $array;
}

$xml = simplexml_load_string($buffer);
$array = XML2Array($xml);
$array = array($xml->getName() => $array);

var_dump($array);

Here's what happened:
10ca46c526.png
Immediately there was a problem. I needed everyone to convert to array like [0], [1], [2] and so on (the array elements), but it turned out that the same item appeared the rest of the elements (under the numbers: [0], [1], [2] and so on).
How to do what I wrote above? Please help!
In the array it should look something like this:
16e0e457b0.png
March 20th 20 at 11:32
0 answer

Find more questions by tags PHPHTMLArrays