php - replace first occurrence from right and left side of string -


i tried replace first occurance of json string { right side, , left side } .

$json_data = preg_replace( '/\{/' , '', $json_data ,1 ); $json_data = rtrim( $json_data ,'}' ); // here issue 

but string {"chart":"c12","series":{"name":"test","data":[]}} replaced

"chart":"c12","series":{"name":"test","data":[] 

the rtrim replaced '}}' . how replace first occurance of } right side of string ?

$json_data = preg_replace('/^\s*\{\s*(.+)\s*\}\s*$/', '$1', $json_data); 

however, it's difficult imagine situation when it's necessary.


Comments

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -