XMl
like below,
<text font-family="Helvetica" font-size="25" style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: rgb(0,0,0); fill-rule: nonzero; opacity: 1;" >
<tspan x="-100" y="7.87" style="stroke: none; stroke-width: 0; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 4; fill: rgb(0,0,0); fill-rule: ; opacity: 1;">t</tspan>
<tspan x="-93" y="7.87" style="stroke: none; stroke-width: 0; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 4; fill: rgb(0,0,0); fill-rule: ; opacity: 1;">e</tspan>
<tspan x="-79" y="7.87" style="stroke: none; stroke-width: 0; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 4; fill: rgb(0,0,0); fill-rule: ; opacity: 1;">s</tspan>
<tspan x="-66" y="7.87" style="stroke: none; stroke-width: 0; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 4; fill: rgb(0,0,0); fill-rule: ; opacity: 1;">t</tspan>
</text>
What i want to do is, keep first tspan
and append all other tspan
value on first tspan
and remove all other.
He is the desired output,
<text font-family="Helvetica" font-size="25" style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: rgb(0,0,0); fill-rule: nonzero; opacity: 1;" >
<tspan x="-100" y="7.87" style="stroke: none; stroke-width: 0; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 4; fill: rgb(0,0,0); fill-rule: ; opacity: 1;">test</tspan>
</text>
For this what i did,
$previousValue = null;
$first = $text->tspan[0];
foreach($text->tspan as $k2=>$span){
if(is_object($span)){
$style = $span->attributes()->style;
if($previousValue) {
if(strcmp($style,$previousValue) === 0){
$first.=$span;
//$dom=dom_import_simplexml($span); $dom->parentNode->removeChild($dom);
}
}
$previousValue = $style;
}
}
$text->tspan[0] = $first;
That will generate first node perfect, but not removing other nodes proper. I tried this even,
$dom=dom_import_simplexml($span); $dom->parentNode->removeChild($dom);
But it just removing 1 node and break the loop then. Dont know what happening there. Am i doing any mistake there?