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>) 

tested here - regex101

$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

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -