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

authentication - Mongodb revoke acccess to connect test database -

r - Update two sets of radiobuttons reactively - shiny -

ios - Realm over CoreData should I use NSFetchedResultController or a Dictionary? -