php - replace xml/svg element attribute for specific element only -
i have 'xml` this,
<text>     <tspan fill='rgba(0,0,0,0)'>abc</tspan> </text> <rect fill='rgba(0,0,0,0)'></rect>   i trying replace rgba( rgb(, replacing instances occur in data. want replace instances tspan tag only. tried str_replace replacing instances data.
output should this
<text>     <tspan fill='rgb(0,0,0,0)'>abc</tspan> </text> <rect fill='rgba(0,0,0,0)'></rect>      
try regexp:
rgba(?=(.*)<\/tspan>)     $re = "/rgba(?=(.*)<\\/tspan>)/";  $str = "<text><tspan stroke='' opacity='' fill='rgba(0,0,0,0)'>abc</tspan><tspan fill='rgba(0,0,0,0)'><h1>anything</h1></tspan></text><rect fill='rgba(0,0,0,0)'></rect>";  $subst = "rgb";   $result = preg_replace($re, $subst, $str);      
Comments
Post a Comment