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
Post a Comment