I have an xml witch contains value and children element as you can see below:
<rk id="1" type="seg">
some text <g id="11">italic text</g> other text
</rk>
And i have to get both the values and children elements in order:
$arr = [
'value1' => 'some text ',
'children' => '<g id="11">italic text</g>',
'value2' => ' other text'
];
The main goal is to be able to put this back to the xml file in the correct order, after we changed the values.
If you want to see more accurate example here is a code on top with the xml and below with the php counter part of it:
<source>
<x id="10">
<rk id="1" type="seg">
some text<g id="11">italic text</g> other text
</rk>
</x>
<rk id="2">
text <g id="12">italic text</g>
</rk>
</source>*/
$source = [
0 => [
'tag' => 'x',
'attrs' => [
0 => [
'name' => 'id',
'value' => '10'
]
],
'childrens' => [
0 => [
'tag' => 'rk',
'attrs' => [
0 => [
'name' => 'id',
'value' => '1'
],
1 => [
'name' => 'type',
'value' => 'seg'
]
],
'value1' => 'some text ',
'childrens' => [
0 => [
'tag' => 'g',
'attrs' => [
0 => [
'name' => 'id',
'value' => '10'
]
],
'value' => 'italic text',
'childrens' => []
],
],
'value2' => ' other text',
]
]
],
1 => [
'tag' => 'rk',
'attrs' => [
0 => [
'name' => 'id',
'value' => '2'
],
1 => [
'name' => 'type',
'value' => 'seg'
]
],
'value1' => 'text',
'childrens' => [
0 => [
'tag' => 'g',
'attrs' => [
0 => [
'name' => 'id',
'value' => '12'
]
],
'value' => 'italic text',
'childrens' => []
],
],
]
];