I work with xml file that looks like this:
<text>
<paragraph/>
First text
<paragraph/>
Second text
</text>
<text>
<paragraph/>
Third text
<paragraph/>
Fourth text
</text>
I need to get the value of text element but the result should be in 4 rows. So every <paragraph/>
element starts new row:
1 | First text
2 | Second text
3 | Third text
4 | Fourth text
My code:
$filexml = File::get('../file.xml');
$xml = simplexml_load_string($filexml);
for ($i=1; $i < count($xml->text) + 1; $i++) {
foreach ($xml->text as $text_item) {
echo $i++." | ".$text_item."<br/>";
}
}
My result:
1 | First text Second text
2 | Third text Fourth text
What should I do next? Or maybe there is different approach how can I achieve the desired result?